Class: RememberTheMilkTask

Inherits:
RememberTheMilkHash show all
Includes:
Comparable
Defined in:
lib/thartmx_lib.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.



536
537
538
539
# File 'lib/thartmx_lib.rb', line 536

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.



530
531
532
# File 'lib/thartmx_lib.rb', line 530

def rtm
  @rtm
end

Instance Method Details

#<=>(other) ⇒ Object



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'lib/thartmx_lib.rb', line 572

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)


549
# File 'lib/thartmx_lib.rb', line 549

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

#dueObject



545
# File 'lib/thartmx_lib.rb', line 545

def due() task.due  end

#due_displayObject



558
559
560
561
562
563
564
565
566
567
568
# File 'lib/thartmx_lib.rb', line 558

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)


547
# File 'lib/thartmx_lib.rb', line 547

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

#has_due_time?Boolean

Returns:

  • (Boolean)


548
# File 'lib/thartmx_lib.rb', line 548

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

#list_idObject



544
# File 'lib/thartmx_lib.rb', line 544

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.


630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/thartmx_lib.rb', line 630

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



541
# File 'lib/thartmx_lib.rb', line 541

def task() tasks[-1] end

#task_idObject



543
# File 'lib/thartmx_lib.rb', line 543

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

#taskseries_idObject



542
# File 'lib/thartmx_lib.rb', line 542

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

#timelineObject



532
533
534
# File 'lib/thartmx_lib.rb', line 532

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

#to_sObject



550
551
552
553
554
555
556
# File 'lib/thartmx_lib.rb', line 550

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