class Medo::Task
Attributes
clock[RW]
completed_at[R]
created_at[R]
description[R]
notes[R]
Public Class Methods
from_attributes(attributes)
click to toggle source
# File lib/medo/task.rb, line 12 def from_attributes(attributes) task = Task.new(attributes.delete("description"), attributes) task.instance_eval do @created_at = attributes["created_at"] or raise ArgumentError, "Missing created_at" @done = attributes["done"] @completed_at = attributes["completed_at"] or raise ArgumentError, "Missing completed_at" if @done end task end
new(description, options = {})
click to toggle source
# File lib/medo/task.rb, line 24 def initialize(description, options = {}) self.description = description @created_at = clock.now @completed_at = nil self.notes = options["notes"] || options[:notes] end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/medo/task.rb, line 31 def <=>(other) unless other.kind_of?(Task) raise ArgumentError, "comparison of #{self.class.name} with #{other.class.name} failed" end case [self.completed_at.nil?, other.completed_at.nil?] when [true, true] then (self.created_at <=> other.created_at) * -1 when [false, false] then (self.completed_at <=> other.completed_at) * -1 when [true, false] then -1 when [false, true] then 1 end end
==(other)
click to toggle source
# File lib/medo/task.rb, line 44 def ==(other) return true if other.equal? self return false unless other.kind_of?(self.class) self.description == other.description && self.created_at == other.created_at && self.done? == other.done? && self.completed_at == other.completed_at && self.notes == other.notes end
description=(desc)
click to toggle source
# File lib/medo/task.rb, line 62 def description=(desc) description = desc.to_s.strip raise ArgumentError, "No description given!" if description.empty? @description = description end
done()
click to toggle source
# File lib/medo/task.rb, line 72 def done @completed_at = clock.now @done = true end
done?()
click to toggle source
# File lib/medo/task.rb, line 82 def done? !!@done end
initialize_copy(source)
click to toggle source
Calls superclass method
# File lib/medo/task.rb, line 54 def initialize_copy(source) super @description = @description.dup @created_at = @created_at.dup @completed_at = @completed_at.dup if @completed_at @notes = @notes.dup end
notes=(*args)
click to toggle source
# File lib/medo/task.rb, line 68 def notes=(*args) @notes = Notes.new(*args) end
reset()
click to toggle source
# File lib/medo/task.rb, line 77 def reset @completed_at = nil @done = false end
Private Instance Methods
clock()
click to toggle source
# File lib/medo/task.rb, line 88 def clock self.class.clock end