Class: Cue::Item
- Inherits:
-
Object
show all
- Includes:
- ColorFool, Comparable
- Defined in:
- lib/cue/item.rb
Constant Summary
Constants included
from ColorFool
ColorFool::CODES, ColorFool::COLORS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from ColorFool
#code, #colorize
Constructor Details
#initialize(content, attrs = {}) ⇒ Item
Returns a new instance of Item.
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cue/item.rb', line 13
def initialize(content, attrs={})
self.content = content
attrs.each do |k, v|
setter = "#{k}="
if respond_to?(setter, true)
send(setter, v)
end
end
self.state = self.state || :incomplete
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
10
11
12
|
# File 'lib/cue/item.rb', line 10
def content
@content
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
11
12
13
|
# File 'lib/cue/item.rb', line 11
def created_at
@created_at
end
|
#state ⇒ Object
Returns the value of attribute state.
11
12
13
|
# File 'lib/cue/item.rb', line 11
def state
@state
end
|
Instance Method Details
#<=>(other) ⇒ Object
26
27
28
|
# File 'lib/cue/item.rb', line 26
def <=>(other)
created_at <=> other.created_at
end
|
#==(other) ⇒ Object
30
31
32
|
# File 'lib/cue/item.rb', line 30
def ==(other)
content == other.content
end
|
#complete! ⇒ Object
34
35
36
|
# File 'lib/cue/item.rb', line 34
def complete!
self.state = :complete
end
|
#complete? ⇒ Boolean
38
39
40
|
# File 'lib/cue/item.rb', line 38
def complete?
self.state == :complete
end
|
#hash ⇒ Object
42
43
44
|
# File 'lib/cue/item.rb', line 42
def hash
Digest::SHA1.hexdigest(content)
end
|
#in_store?(store) ⇒ Boolean
46
47
48
|
# File 'lib/cue/item.rb', line 46
def in_store?(store)
!store.read(hash).nil?
end
|
#incomplete! ⇒ Object
50
51
52
|
# File 'lib/cue/item.rb', line 50
def incomplete!
self.state = :incomplete
end
|
#incomplete? ⇒ Boolean
54
55
56
|
# File 'lib/cue/item.rb', line 54
def incomplete?
self.state == :incomplete
end
|
#save(store) ⇒ Object
58
59
60
61
62
|
# File 'lib/cue/item.rb', line 58
def save(store)
self.created_at = Time.now unless in_store?(store)
store.write(hash, self)
true
end
|
#to_s ⇒ Object
64
65
66
67
68
|
# File 'lib/cue/item.rb', line 64
def to_s
i = Indicator.new(state)
h = colorize(:cyan) { hash[0..6] }
"#{h} #{i} #{content}"
end
|
#toggle! ⇒ Object
70
71
72
73
|
# File 'lib/cue/item.rb', line 70
def toggle!
complete? ? incomplete! : complete!
self
end
|