Class: Toodledo::Task
- Inherits:
-
Object
- Object
- Toodledo::Task
- Defined in:
- lib/toodledo/task.rb
Overview
A read only representation of a Task. This has some sugar in it to return relevant Context, Folder and Goal objects instead of their underlying ids.
Constant Summary collapse
- ONLY =
Indicates that this task can only be completed on the given duedate. See www.toodledo.com/info/help.php?sel=42
'='
- EARLIEST =
Indicates that the earliest the task can be completed is the duedate. See www.toodledo.com/info/help.php?sel=42
'<'
- OPTIONAL =
Indicates that the task’s duedate is optional. See www.toodledo.com/info/help.php?sel=42
'?'
Instance Attribute Summary collapse
-
#added ⇒ Object
readonly
Returns the value of attribute added.
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#duedate ⇒ Object
readonly
Returns the value of attribute duedate.
-
#duedatemodifier ⇒ Object
readonly
Returns the value of attribute duedatemodifier.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#modified ⇒ Object
readonly
Returns the value of attribute modified.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#repeat ⇒ Object
readonly
Returns the value of attribute repeat.
-
#star ⇒ Object
readonly
Returns the value of attribute star.
-
#startdate ⇒ Object
readonly
Returns the value of attribute startdate.
-
#status ⇒ Object
readonly
as of 3.90.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.parse(session, el) ⇒ Object
Parses a task element and returns a new Task.
-
.parse_deleted(session, el) ⇒ Object
Returns a hash containing :id and :stamp, a timestamp showing when the task was deleted.
Instance Method Summary collapse
- #completed? ⇒ Boolean
- #context ⇒ Object
- #folder ⇒ Object
- #goal ⇒ Object
-
#initialize(id, params = {}) ⇒ Task
constructor
TODO Repetitious.
- #is_parent? ⇒ Boolean
- #num_children ⇒ Object
- #server_id ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(id, params = {}) ⇒ Task
TODO Repetitious. Refactor
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/toodledo/task.rb', line 59 def initialize(id, params = {}) @id = id @title = params[:title] @tag = params[:tag] @parent_id = params[:parent_id] @parent = params[:parent] @num_children = params[:num_children] # The folder, context and goals are parsed out from get_tasks() call into # the appropriate object. @folder = params[:folder] @context = params[:context] @goal = params[:goal] @added = params[:added] @modified = params[:modified] @completed = params[:completed] @duedate = params[:duedate] @duedatemodifier = params[:duedatemodifier] @duetime = params[:duetime] @repeat = params[:repeat] @priority = params[:priority] @length = params[:length] @timer = params[:timer] @note = params[:note] @startdate = params[:startdate] @status = params[:status] @star = params[:star] end |
Instance Attribute Details
#added ⇒ Object (readonly)
Returns the value of attribute added.
27 28 29 |
# File 'lib/toodledo/task.rb', line 27 def added @added end |
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
27 28 29 |
# File 'lib/toodledo/task.rb', line 27 def completed @completed end |
#duedate ⇒ Object (readonly)
Returns the value of attribute duedate.
28 29 30 |
# File 'lib/toodledo/task.rb', line 28 def duedate @duedate end |
#duedatemodifier ⇒ Object (readonly)
Returns the value of attribute duedatemodifier.
28 29 30 |
# File 'lib/toodledo/task.rb', line 28 def duedatemodifier @duedatemodifier end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
30 31 32 |
# File 'lib/toodledo/task.rb', line 30 def length @length end |
#modified ⇒ Object (readonly)
Returns the value of attribute modified.
27 28 29 |
# File 'lib/toodledo/task.rb', line 27 def modified @modified end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
31 32 33 |
# File 'lib/toodledo/task.rb', line 31 def note @note end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
26 27 28 |
# File 'lib/toodledo/task.rb', line 26 def parent @parent end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
26 27 28 |
# File 'lib/toodledo/task.rb', line 26 def parent_id @parent_id end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
29 30 31 |
# File 'lib/toodledo/task.rb', line 29 def priority @priority end |
#repeat ⇒ Object (readonly)
Returns the value of attribute repeat.
29 30 31 |
# File 'lib/toodledo/task.rb', line 29 def repeat @repeat end |
#star ⇒ Object (readonly)
Returns the value of attribute star.
36 37 38 |
# File 'lib/toodledo/task.rb', line 36 def star @star end |
#startdate ⇒ Object (readonly)
Returns the value of attribute startdate.
35 36 37 |
# File 'lib/toodledo/task.rb', line 35 def startdate @startdate end |
#status ⇒ Object (readonly)
as of 3.90
34 35 36 |
# File 'lib/toodledo/task.rb', line 34 def status @status end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
26 27 28 |
# File 'lib/toodledo/task.rb', line 26 def tag @tag end |
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
30 31 32 |
# File 'lib/toodledo/task.rb', line 30 def timer @timer end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
26 27 28 |
# File 'lib/toodledo/task.rb', line 26 def title @title end |
Class Method Details
.parse(session, el) ⇒ Object
Parses a task element and returns a new Task.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/toodledo/task.rb', line 126 def self.parse(session, el) # #-- <task> # <id>1234</id> # <parent>1122</parent> # <children>0</children> # <title>Buy Milk</title> # <tag>After work</tag> # Actually, this counts as two tags # <folder>123</folder> # <context id="123">Home</context> # <goal id="123">Get a Raise</goal> # <added>2006-01-23</added> # <modified>2006-01-25 05:12:45</modified> # <duedate modifier="=">2006-01-25</duedate> # <duetime>2:00pm</duetime> # <completed>2008-01-20</completed> # <repeat>1</repeat> # <priority>2</priority> # <length>20</length> # <timer onfor=''>0</timer> # <note></note> # <startdate></startdate> # <status>0</status> # <star></star> # </task> #++ id = el.elements['id'].text folder_id = el.elements['folder'].text folder = session.get_folder_by_id(folder_id); if (folder == nil) folder = Folder::NO_FOLDER end goal_id = el.elements['goal'].attributes['id'] goal = session.get_goal_by_id(goal_id) if (goal == nil) goal = Goal::NO_GOAL end context_id = el.elements['context'].attributes['id'] context = session.get_context_by_id(context_id) if (context == nil) context = Context::NO_CONTEXT end duedatemodifier = nil duedate = el.elements['duedate'].text if (duedate != nil) duedatemodifier = el.elements['duedate'].attribute('modifier') duetime = el.elements['duetime'].text if (duetime != nil) duedate += " #{duetime}" fmt = Session::DATE_FORMAT + ' ' + Session::TIME_FORMAT duedate = DateTime.strptime(duedate, fmt) else fmt = Session::DATE_FORMAT duedate = DateTime.strptime(duedate, fmt) end end added = el.elements['added'].text if (added != nil) added = Date.strptime(added, Session::DATE_FORMAT) end modified = el.elements['modified'].text if (modified != nil) modified = DateTime.strptime(modified, Session::DATETIME_FORMAT) end completed = el.elements['completed'].text if (completed != nil) completed = Date.strptime(completed, Session::DATE_FORMAT) end repeat = el.elements['repeat'].text.to_i priority = el.elements['priority'].text.to_i # Only set a parent if it's not the 'empty parent'. parent_id_el = el.elements['parent'] if (parent_id_el != nil) parent_id = parent_id_el.text if parent_id == '0' parent_id = nil else parent_id = parent_id.to_i parent = session.get_task_by_id(parent_id) end else parent_id = nil end # This is actually the NUMBER of children. Two children returns 2. num_children = el.elements['children'].text.to_i title = el.elements['title'].text tag = el.elements['tag'].text if tag == '0' tag = nil elsif tag tag = tag.split(/\s+/) end length = el.elements['length'].text length = nil if (length == '0') timer = el.elements['timer'].text timer = nil if (timer == '0') note = el.elements['note'].text note = nil if (note == '0') startdate = el.elements['startdate'].text if (startdate != nil) startdate = Date.strptime(startdate, Session::DATE_FORMAT) end status = el.elements['status'].text.to_i status = Status::NONE if (status == 0) star = (el.elements['star'].text.to_i == 1) params = { :parent_id => parent_id, :parent => parent, :num_children => num_children, :title => title, :tag => tag, :folder => folder, :context => context, :goal => goal, :added => added, :modified => modified, :duedate => duedate, :duedatemodifier => duedatemodifier, :completed => completed, :repeat => repeat, :priority => priority, :length => length, :timer => timer, :note => note, :startdate => startdate, :status => status, :star => star } return Task.new(id, params) end |
.parse_deleted(session, el) ⇒ Object
Returns a hash containing :id and :stamp, a timestamp showing when the task was deleted.
<task>
<id>12345</id>
<stamp>2008-02-25 07:46:42</stamp>
</task>
<task>
<id>67890</id>
<stamp>2008-03-12 14:11:12</stamp>
</task>
115 116 117 118 119 120 121 122 123 |
# File 'lib/toodledo/task.rb', line 115 def self.parse_deleted(session, el) id = el.elements['id'].text stamp = el.elements['stamp'].text fmt = Session::DATETIME_FORMAT deleted_stamp = DateTime.strptime(stamp, fmt) return { :id => id, :stamp => deleted_stamp } end |
Instance Method Details
#completed? ⇒ Boolean
96 97 98 |
# File 'lib/toodledo/task.rb', line 96 def completed? return @completed != nil end |
#context ⇒ Object
42 43 44 |
# File 'lib/toodledo/task.rb', line 42 def context return @context end |
#folder ⇒ Object
46 47 48 |
# File 'lib/toodledo/task.rb', line 46 def folder return @folder end |
#goal ⇒ Object
50 51 52 |
# File 'lib/toodledo/task.rb', line 50 def goal return @goal end |
#is_parent? ⇒ Boolean
100 101 102 |
# File 'lib/toodledo/task.rb', line 100 def is_parent? return ! (@num_children == nil || @num_children == 0) end |
#num_children ⇒ Object
54 55 56 |
# File 'lib/toodledo/task.rb', line 54 def num_children return @num_children end |
#server_id ⇒ Object
38 39 40 |
# File 'lib/toodledo/task.rb', line 38 def server_id return @id end |
#to_xml ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/toodledo/task.rb', line 278 def to_xml() # XXX Need to make this be contextual. #<task> # <id>#{@id}</id> # <parent>#{@parent_id}</parent> # <children>#{@children}</children> # <title>#{@title}</title> # <tag>#{@tag.join(' ')}</tag> # <folder>#{@folder.server_id}</folder> # <context id="#{@context.server_id}">#{@context.name}</context> # <goal id="#{@goal.server_id}">#{@goal.name}</goal> # <added>#{@added}</added> # <modified>#{@modified}</modified> # <duedate modifier="@duedatemodifier">#{@duedate.strftime(Session::DATE_FORMAT)}</duedate> # <duetime>#{@duedate.strftime(Session::TIME_FORMAT)}</duetime> # <completed>#{@completed}</completed> # <repeat>#{@repeat}</repeat> # <priority>#{@priority}</priority> # <length>#{@length}</length> # <timer>#{@timer}</timer> # <note>#{@note}</note> # #</task> return 'implement me!' end |