Class: RTM::Task

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/rtmilk/api/tasks.rb

Overview

Task class. Unfortunately, RTM API defines this object as TaskSeries. That seemes to be unnatural.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Task

create a Task.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rtmilk/api/tasks.rb', line 111

def initialize(arg)
   assert_equal(Hash, arg.class)

   @list = if arg.has_key? :list
      arg[:list]
   else
      RTM::List.inbox['id']
   end

   if arg.has_key? :name  # create from scratch
      result,transaction = RTM::Tasks::Add.new(
         RTM::API.token,
         RTM::Timeline.new(RTM::API.token).to_s,
         @list, arg[:name]).invoke
      @taskseries = result['taskseries'].first
      assert(@list, result['id'])
      create_chunks
      @notes = []
   else 
      assert(arg.has_key?(:taskseries))
      @taskseries = arg[:taskseries]
      create_chunks
      create_notes
   end
end

Instance Attribute Details

#chunksObject (readonly)

Returns the value of attribute chunks.



62
63
64
# File 'lib/rtmilk/api/tasks.rb', line 62

def chunks
  @chunks
end

#listObject (readonly)

Returns the value of attribute list.



62
63
64
# File 'lib/rtmilk/api/tasks.rb', line 62

def list
  @list
end

#notesObject (readonly)

Returns the value of attribute notes.



62
63
64
# File 'lib/rtmilk/api/tasks.rb', line 62

def notes
  @notes
end

Class Method Details

.find(arg) ⇒ Object

find a Task by name.



76
77
78
79
80
# File 'lib/rtmilk/api/tasks.rb', line 76

def Task.find(arg)
   all_tasks(arg[:list]).find do |task|
      task.name =~ /#{arg[:name]}/
   end
end

.find_all(arg) ⇒ Object

find all tasks by list, and name



83
84
85
86
87
88
89
90
91
92
# File 'lib/rtmilk/api/tasks.rb', line 83

def Task.find_all(arg)
   tasks = all_tasks(arg[:list])
   if arg.has_key? :name
      tasks.find_all do |task|
         task['name'] =~ /#{arg[:name]}/
      end
   else
      tasks
   end
end

Instance Method Details

#addNote(arg) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/rtmilk/api/tasks.rb', line 142

def addNote(arg)
   assert_equal(Hash, arg.class)

   n = RTM::Note.new(
      :task => self,
      :title => arg[:title], 
      :body  => arg[:body])
   @notes.push n
end

#createdObject



72
# File 'lib/rtmilk/api/tasks.rb', line 72

def created; @taskseries['created']; end

#deleteObject

delete a Task and its all chunks.



138
139
140
# File 'lib/rtmilk/api/tasks.rb', line 138

def delete
   chunks.collect { |chunk| chunk.delete(id, @list) }
end

#idObject



67
# File 'lib/rtmilk/api/tasks.rb', line 67

def id; @taskseries['id']; end

#modifiedObject



68
# File 'lib/rtmilk/api/tasks.rb', line 68

def modified; @taskseries['modified']; end

#nameObject



66
# File 'lib/rtmilk/api/tasks.rb', line 66

def name; @taskseries['name']; end

#participantsObject



70
# File 'lib/rtmilk/api/tasks.rb', line 70

def participants; @taskseries['participants']; end

#sourceObject



73
# File 'lib/rtmilk/api/tasks.rb', line 73

def source; @taskseries['source']; end

#tagsObject



69
# File 'lib/rtmilk/api/tasks.rb', line 69

def tags; @taskseries['tags']; end

#urlObject



71
# File 'lib/rtmilk/api/tasks.rb', line 71

def url; @taskseries['url']; end