Class: RememberTheMilkTask

Inherits:
RememberTheMilkHash show all
Includes:
Comparable
Defined in:
lib/rtmapi.rb

Overview

The API is aware it’s creating tasks. You may want to add semantics to a “task” elsewhere in your program. This gives you that flexibility plus, we’ve added some helper methods

Constant Summary collapse

@@BeginningOfEpoch =

kludgey.. sure. life’s a kludge. deal with it.

Time.parse("Jan 1 1904")

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RememberTheMilkHash

#arrayify_value, #id, #method_missing, #rtm_id, strict_keys=

Constructor Details

#initialize(rtm_api_handle = nil) ⇒ RememberTheMilkTask

Returns a new instance of RememberTheMilkTask.



510
511
512
513
# File 'lib/rtmapi.rb', line 510

def initialize( rtm_api_handle=nil )
  super
  @rtm = rtm_api_handle   # keep track of this so we can do setters (see factory below)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RememberTheMilkHash

Instance Attribute Details

#rtmObject

Returns the value of attribute rtm.



504
505
506
# File 'lib/rtmapi.rb', line 504

def rtm
  @rtm
end

Instance Method Details

#<=>(other) ⇒ Object



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/rtmapi.rb', line 546

def <=>(other)
  due = (has_key?(:tasks) && tasks.class == Array) ? task[:due] : nil
  due = @@BeginningOfEpoch unless due.class == Time
  other_due = (other.has_key?(:tasks) && other.tasks.class == Array) ? other.task[:due] : nil
  other_due = @@BeginningOfEpoch unless other_due.class == Time

  # sort based on priority, then due date, then name
  # which is the rememberthemilk default
  # if 0 was false in ruby, we could have done
  # prio <=> other_due || due <=> other_due || self['name'].to_s <=> other['name'].to_s
  # but it's not, so oh well....
  prio = priority.to_i
  prio += 666 if prio == 0  # prio of 0 is no priority which means it should show up below 1-3
  other_prio = other.priority.to_i
  other_prio += 666 if other_prio == 0

  if prio != other_prio
    return prio <=> other_prio
  elsif due != other_due
    return due <=> other_due
  else 
    # TODO: should this be case insensitive?  
    return self[:name].to_s <=> other[:name].to_s
  end
end

#complete?Boolean

Returns:

  • (Boolean)


523
# File 'lib/rtmapi.rb', line 523

def complete?()     task[:completed] != ''          end

#dueObject



519
# File 'lib/rtmapi.rb', line 519

def due() task.due  end

#due_displayObject



532
533
534
535
536
537
538
539
540
541
542
# File 'lib/rtmapi.rb', line 532

def due_display
  if has_due? 
    if has_due_time?
      due.strftime("%a %d %b %y at %I:%M%p")
    else
      due.strftime("%a %d %b %y")
    end
  else 
    '[no due date]'
  end
end

#has_due?Boolean

Returns:

  • (Boolean)


521
# File 'lib/rtmapi.rb', line 521

def has_due?()      due.class == Time                end

#has_due_time?Boolean

Returns:

  • (Boolean)


522
# File 'lib/rtmapi.rb', line 522

def has_due_time?() task.has_due_time == '1'         end

#list_idObject



518
# File 'lib/rtmapi.rb', line 518

def list_id() parent_list end

#moveTo(to_list_id, args = {}) ⇒ Object

We have to do this because moveTo takes a “from_list_id”, not “list_id”, so the above factory

wouldn't work.  sigh.


604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/rtmapi.rb', line 604

def moveTo( to_list_id, args = {} )
  if @rtm == nil
    raise RememberTheMilkAPIError.new( :code => '667', :msg => "moveTO called without a handle to an rtm object [#{self.to_s}]" )
  end
  method_args = {}
  method_args[:timeline] = timeline
  method_args[:from_list_id] = list_id
  method_args[:to_list_id] = to_list_id
  method_args[:taskseries_id] = taskseries_id
  method_args[:task_id] = task_id
  method_args.merge( args )
  @rtm.call_api_method( :moveTo, method_args )
end

#taskObject



515
# File 'lib/rtmapi.rb', line 515

def task() tasks[-1] end

#task_idObject



517
# File 'lib/rtmapi.rb', line 517

def task_id() self.has_key?(:task_id) ? self[:task_id] : task.rtm_id end

#taskseries_idObject



516
# File 'lib/rtmapi.rb', line 516

def taskseries_id() self.has_key?(:taskseries_id) ? self[:taskseries_id] : rtm_id end

#timelineObject



506
507
508
# File 'lib/rtmapi.rb', line 506

def timeline
  @timeline ||= rtm.get_timeline  # this caches timelines per user
end

#to_sObject



524
525
526
527
528
529
530
# File 'lib/rtmapi.rb', line 524

def to_s
  a_parent_list = self[:parent_list] || '<Parent Not Set>'
  a_taskseries_id = self[:taskseries_id] || self[:id] || '<No Taskseries Id>'
  a_task_id = self[:task_id] || (self[:task] && self[:task].rtm_td) || '<No Task Id>' 
  a_name = self[:name] || '<Name Not Set>'
  "#{a_parent_list}/#{a_taskseries_id}/#{a_task_id}: #{a_name}"
end