class Cue::Item

Attributes

content[RW]
created_at[RW]
state[RW]

Public Class Methods

new(content, attrs={}) click to toggle source
# 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

Public Instance Methods

<=>(other) click to toggle source
# File lib/cue/item.rb, line 26
def <=>(other)
  created_at <=> other.created_at
end
==(other) click to toggle source
# File lib/cue/item.rb, line 30
def ==(other)
  content == other.content
end
complete!() click to toggle source
# File lib/cue/item.rb, line 34
def complete!
  self.state = :complete
end
complete?() click to toggle source
# File lib/cue/item.rb, line 38
def complete?
  self.state == :complete
end
hash() click to toggle source
# File lib/cue/item.rb, line 42
def hash
  Digest::SHA1.hexdigest(content)
end
in_store?(store) click to toggle source
# File lib/cue/item.rb, line 46
def in_store?(store)
  !store.read(hash).nil?
end
incomplete!() click to toggle source
# File lib/cue/item.rb, line 50
def incomplete!
  self.state = :incomplete
end
incomplete?() click to toggle source
# File lib/cue/item.rb, line 54
def incomplete?
  self.state == :incomplete
end
save(store) click to toggle source
# 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() click to toggle source
# 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!() click to toggle source
# File lib/cue/item.rb, line 70
def toggle!
  complete? ? incomplete! : complete!
  self
end