Class: Medo::Task
Class Attribute Summary collapse
-
.clock ⇒ Object
Returns the value of attribute clock.
Instance Attribute Summary collapse
-
#completed_at ⇒ Object
readonly
Returns the value of attribute completed_at.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#notes ⇒ Object
Returns the value of attribute notes.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #done ⇒ Object
- #done? ⇒ Boolean
-
#initialize(description, options = {}) ⇒ Task
constructor
A new instance of Task.
- #initialize_copy(source) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(description, options = {}) ⇒ Task
24 25 26 27 28 29 |
# File 'lib/medo/task.rb', line 24 def initialize(description, = {}) self.description = description @created_at = clock.now @completed_at = nil self.notes = ["notes"] || [:notes] end |
Class Attribute Details
.clock ⇒ Object
Returns the value of attribute clock.
10 11 12 |
# File 'lib/medo/task.rb', line 10 def clock @clock end |
Instance Attribute Details
#completed_at ⇒ Object (readonly)
Returns the value of attribute completed_at.
7 8 9 |
# File 'lib/medo/task.rb', line 7 def completed_at @completed_at end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/medo/task.rb', line 7 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/medo/task.rb', line 7 def description @description end |
#notes ⇒ Object
Returns the value of attribute notes.
7 8 9 |
# File 'lib/medo/task.rb', line 7 def notes @notes end |
Class Method Details
.from_attributes(attributes) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# 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) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# 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 |
#done ⇒ Object
72 73 74 75 |
# File 'lib/medo/task.rb', line 72 def done @completed_at = clock.now @done = true end |
#done? ⇒ Boolean
82 83 84 |
# File 'lib/medo/task.rb', line 82 def done? !!@done end |
#initialize_copy(source) ⇒ Object
54 55 56 57 58 59 60 |
# 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 |
#reset ⇒ Object
77 78 79 80 |
# File 'lib/medo/task.rb', line 77 def reset @completed_at = nil @done = false end |