Class: Things::Task
Constant Summary collapse
- INCOMPLETED =
0- CANCELED =
2- COMPLETED =
3
Instance Method Summary collapse
- #<=>(another) ⇒ Object
- #bullet ⇒ Object
- #canceled? ⇒ Boolean
- #children ⇒ Object
- #children? ⇒ Boolean
- #children_ids ⇒ Object
- #completed? ⇒ Boolean (also: #complete?, #done?)
- #due? ⇒ Boolean
- #due_date ⇒ Object
- #incompleted? ⇒ Boolean (also: #incomplete?)
-
#initialize(task_xml, doc) ⇒ Task
constructor
A new instance of Task.
- #notes ⇒ Object
- #notes? ⇒ Boolean
- #parent ⇒ Object
- #parent? ⇒ Boolean
- #parent_id ⇒ Object
- #position ⇒ Object (also: #index, #order)
- #scheduled? ⇒ Boolean
- #scheduled_date ⇒ Object
- #status ⇒ Object
- #tag?(name) ⇒ Boolean
- #tag_ids ⇒ Object
- #tags ⇒ Object
- #tags? ⇒ Boolean
- #title ⇒ Object (also: #to_s)
- #to_xml ⇒ Object
Constructor Details
#initialize(task_xml, doc) ⇒ Task
Returns a new instance of Task.
9 10 11 12 |
# File 'lib/things/task.rb', line 9 def initialize(task_xml, doc) @doc = doc @xml_node = task_xml end |
Instance Method Details
#<=>(another) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/things/task.rb', line 20 def <=>(another) if parent? && another.parent? parent <=> another.parent else title <=> another.title end end |
#bullet ⇒ Object
115 116 117 |
# File 'lib/things/task.rb', line 115 def bullet completed? ? "✓" : canceled? ? "×" : "-" end |
#canceled? ⇒ Boolean
75 76 77 |
# File 'lib/things/task.rb', line 75 def canceled? status == CANCELED end |
#children ⇒ Object
123 124 125 |
# File 'lib/things/task.rb', line 123 def children @children ||= tasks_from_ids(children_ids) end |
#children? ⇒ Boolean
127 128 129 |
# File 'lib/things/task.rb', line 127 def children? children.any? end |
#children_ids ⇒ Object
119 120 121 |
# File 'lib/things/task.rb', line 119 def children_ids ids_from_relationship('children') end |
#completed? ⇒ Boolean Also known as: complete?, done?
62 63 64 |
# File 'lib/things/task.rb', line 62 def completed? status == COMPLETED end |
#due? ⇒ Boolean
103 104 105 |
# File 'lib/things/task.rb', line 103 def due? due_date && Time.now > due_date end |
#due_date ⇒ Object
99 100 101 |
# File 'lib/things/task.rb', line 99 def due_date @due_date ||= date_attribute("datedue") end |
#incompleted? ⇒ Boolean Also known as: incomplete?
69 70 71 |
# File 'lib/things/task.rb', line 69 def incompleted? status == INCOMPLETED end |
#notes ⇒ Object
79 80 81 82 |
# File 'lib/things/task.rb', line 79 def notes @notes ||= (node = @xml_node.at("attribute[@name='content']")) && Hpricot.parse(node.inner_text.gsub(/\\u3c00/, "<").gsub(/\\u3e00/, ">")).inner_text end |
#notes? ⇒ Boolean
84 85 86 |
# File 'lib/things/task.rb', line 84 def notes? !!notes end |
#parent ⇒ Object
54 55 56 |
# File 'lib/things/task.rb', line 54 def parent @parent ||= task_from_id(parent_id) end |
#parent? ⇒ Boolean
58 59 60 |
# File 'lib/things/task.rb', line 58 def parent? !!parent end |
#parent_id ⇒ Object
50 51 52 |
# File 'lib/things/task.rb', line 50 def parent_id id_from_relationship('parent') end |
#position ⇒ Object Also known as: index, order
92 93 94 |
# File 'lib/things/task.rb', line 92 def position @position ||= @xml_node.at("attribute[@name='index']").inner_text.to_i end |
#scheduled? ⇒ Boolean
111 112 113 |
# File 'lib/things/task.rb', line 111 def scheduled? !!scheduled_date end |
#scheduled_date ⇒ Object
107 108 109 |
# File 'lib/things/task.rb', line 107 def scheduled_date @scheduled_date ||= date_attribute('tickledate') end |
#status ⇒ Object
88 89 90 |
# File 'lib/things/task.rb', line 88 def status @status ||= (node = @xml_node.at("attribute[@name='status']")) && node.inner_text.to_i end |
#tag?(name) ⇒ Boolean
46 47 48 |
# File 'lib/things/task.rb', line 46 def tag?(name) .include?(name) end |
#tag_ids ⇒ Object
32 33 34 |
# File 'lib/things/task.rb', line 32 def tag_ids ids_from_relationship("tags") end |
#tags ⇒ Object
36 37 38 39 40 |
# File 'lib/things/task.rb', line 36 def ||= tag_ids.map do |tag_id| @doc.at("##{tag_id} attribute[@name=title]").inner_text end end |
#tags? ⇒ Boolean
42 43 44 |
# File 'lib/things/task.rb', line 42 def .any? end |
#title ⇒ Object Also known as: to_s
14 15 16 |
# File 'lib/things/task.rb', line 14 def title @xml_node.at("attribute[@name='title']").inner_text end |
#to_xml ⇒ Object
28 29 30 |
# File 'lib/things/task.rb', line 28 def to_xml @xml_node.to_s end |