Class: Things::Task
Constant Summary collapse
- INCOMPLETED =
0
- CANCELED =
2
- COMPLETED =
3
- CHECK_MARK =
"✓"
- X_MARK =
"×"
- MINUS_MARK =
"-"
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.
13 14 15 16 |
# File 'lib/things/task.rb', line 13 def initialize(task_xml, doc) @doc = doc @xml_node = task_xml end |
Instance Method Details
#<=>(another) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/things/task.rb', line 28 def <=>(another) if parent? && another.parent? parent <=> another.parent else title <=> another.title end end |
#bullet ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/things/task.rb', line 123 def bullet case when completed? CHECK_MARK when canceled? X_MARK else MINUS_MARK end end |
#canceled? ⇒ Boolean
83 84 85 |
# File 'lib/things/task.rb', line 83 def canceled? status == CANCELED end |
#children ⇒ Object
138 139 140 |
# File 'lib/things/task.rb', line 138 def children @children ||= tasks_from_ids(children_ids) end |
#children? ⇒ Boolean
142 143 144 |
# File 'lib/things/task.rb', line 142 def children? children.any? end |
#children_ids ⇒ Object
134 135 136 |
# File 'lib/things/task.rb', line 134 def children_ids ids_from_relationship('children') end |
#completed? ⇒ Boolean Also known as: complete?, done?
70 71 72 |
# File 'lib/things/task.rb', line 70 def completed? status == COMPLETED end |
#due? ⇒ Boolean
111 112 113 |
# File 'lib/things/task.rb', line 111 def due? !!due_date && Time.now > due_date end |
#due_date ⇒ Object
107 108 109 |
# File 'lib/things/task.rb', line 107 def due_date @due_date ||= date_attribute("datedue") end |
#incompleted? ⇒ Boolean Also known as: incomplete?
77 78 79 |
# File 'lib/things/task.rb', line 77 def incompleted? status == INCOMPLETED end |
#notes ⇒ Object
87 88 89 90 |
# File 'lib/things/task.rb', line 87 def notes @notes ||= (node = @xml_node.at("attribute[@name='content']")) && Hpricot.parse(node.inner_text.gsub(/\\u3c00/, "<").gsub(/\\u3e00/, ">")).inner_text end |
#notes? ⇒ Boolean
92 93 94 |
# File 'lib/things/task.rb', line 92 def notes? !!notes end |
#parent ⇒ Object
62 63 64 |
# File 'lib/things/task.rb', line 62 def parent @parent ||= task_from_id(parent_id) end |
#parent? ⇒ Boolean
66 67 68 |
# File 'lib/things/task.rb', line 66 def parent? !!parent end |
#parent_id ⇒ Object
58 59 60 |
# File 'lib/things/task.rb', line 58 def parent_id id_from_relationship('parent') end |
#position ⇒ Object Also known as: index, order
100 101 102 |
# File 'lib/things/task.rb', line 100 def position @position ||= @xml_node.at("attribute[@name='index']").inner_text.to_i end |
#scheduled? ⇒ Boolean
119 120 121 |
# File 'lib/things/task.rb', line 119 def scheduled? !!scheduled_date end |
#scheduled_date ⇒ Object
115 116 117 |
# File 'lib/things/task.rb', line 115 def scheduled_date @scheduled_date ||= date_attribute('tickledate') end |
#status ⇒ Object
96 97 98 |
# File 'lib/things/task.rb', line 96 def status @status ||= (node = @xml_node.at("attribute[@name='status']")) && node.inner_text.to_i end |
#tag?(name) ⇒ Boolean
54 55 56 |
# File 'lib/things/task.rb', line 54 def tag?(name) .any? { |t| t.casecmp(name) == 0 } end |
#tag_ids ⇒ Object
40 41 42 |
# File 'lib/things/task.rb', line 40 def tag_ids ids_from_relationship("tags") end |
#tags ⇒ Object
44 45 46 47 48 |
# File 'lib/things/task.rb', line 44 def @tags ||= tag_ids.map do |tag_id| @doc.at("##{tag_id} attribute[@name=title]").inner_text end end |
#tags? ⇒ Boolean
50 51 52 |
# File 'lib/things/task.rb', line 50 def .any? end |
#title ⇒ Object Also known as: to_s
18 19 20 21 22 23 24 |
# File 'lib/things/task.rb', line 18 def title if n = @xml_node.at("attribute[@name='title']") n.inner_text else "FAIL: [#{@xml_node}]" end end |
#to_xml ⇒ Object
36 37 38 |
# File 'lib/things/task.rb', line 36 def to_xml @xml_node.to_s end |