Class: CommandLineInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/thartm.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, token) ⇒ CommandLineInterface

Returns a new instance of CommandLineInterface.



107
108
109
# File 'lib/thartm.rb', line 107

def initialize(key,secret,token)
	@rtm = Rrtm.new(key,secret,token)
end

Instance Method Details

#addObject



167
168
169
# File 'lib/thartm.rb', line 167

def add 
	@rtm.addTask(ARGV[1..-1].join(" "))
end

#color(s, t) ⇒ Object



156
157
158
159
160
161
162
163
164
165
# File 'lib/thartm.rb', line 156

def color(s,t)
    p = case t[:task][0][:priority] 
        when 'N' then printf("\e[0m%s\e[0m",s)
        when '1' then printf("\e[31;40m%s\e[0m",s)
        when '2' then printf("\e[33;40m%s\e[0m",s)
        when '3' then printf("\e[32;40m%s\e[0m",s)
        else puts "err"
    end
    
end

#completeObject



179
180
181
182
183
184
185
# File 'lib/thartm.rb', line 179

def complete
	begin 
	@rtm.completeTask(ARGV[1])
	rescue 
		p "invalid task id"
	end
end

#firstObject



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
# File 'lib/thartm.rb', line 198

def first
	t = Array.new
	tasks = @rtm.tasksAllTaskList	

	tasks.each do |key,val|
		val.each do |k,v|
			t.push(v) unless v.complete? # do not add c ompleted tasks
		end
	end

	# sorting by date (inverse order) and than by task name
	t.sort! do |a,b|
		if (a.has_due? and b.has_due?)
			a.due <=> b.due
		elsif a.has_due?
			-1
	    elsif b.has_due? 
			1
		else
		   a[:name] <=> b[:name] 
		end
	end

	# compose string result
	s = ''
	tt = t[0]
		s +=   tt[:name].to_s + " -- " + tt.due.to_s + "\n"
	puts s
end

#helpObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/thartm.rb', line 228

def help
	s = ''
	s += 'Rrtm: Tha remember the milk Command Line Usage
usage rrtm <command> <params>

help: print this help and exits
lists: show available tasks lists
tasks [list name]: show not completed tasks
add <name>: name can be a task or in the form @list name@ task
add "<name>" : input is better parsed within quotes: task #Listname !priority_value(1..3) 
complete <id>: mark task with id "id" as completed
postpone <id>: postpone task by one day
first: show first uncompleted task
'
puts s
end

#listsObject



171
172
173
174
175
176
177
# File 'lib/thartm.rb', line 171

def lists
	l = @rtm.lists

	l.each do |k,v|
		puts v[:name]
	end
end

#postponeObject



187
188
189
190
191
192
193
# File 'lib/thartm.rb', line 187

def postpone
	begin 
	@rtm.postponeTask(ARGV[1].chomp)
	rescue Exception => e
		p "invalid task id",e
	end
end

#tasksObject



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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/thartm.rb', line 111

def tasks
	t = Array.new
	if ARGV[1]
		l = @rtm.findList(ARGV[1..-1].join(" "))
		begin
			tasks = @rtm.tasks :list_id => l
		rescue Exception => e	
			puts e,"list not found"
			return ''
		end
	else

		tasks = @rtm.tasksAllTaskList	

	end
	tasks.each do |key,val|
		if val.class == RememberTheMilkHash
			val.each do |k,v|
				t.push(v) unless v.complete? # do not add c ompleted tasks
			end
		elsif val.class == RememberTheMilkTask
				t.push(val) unless val.complete? # do not add c ompleted tasks
		end
	end

	# sorting by date (inverse order) and than by task name
	t.sort! do |a,b|
		if (a.has_due? and b.has_due?)
			a.due <=> b.due
		elsif a.has_due?
			-1
	    elsif b.has_due? 
			1
		else
		   a[:name] <=> b[:name] 
		end
	end

	# compose string result
	t.each do |tt|
		s = tt[:id] + ":  "  +   tt[:name].to_s + " -- " + tt.due.to_s + "\n"
           color(s,tt)
	end
end

#tzObject



195
196
197
# File 'lib/thartm.rb', line 195

def tz
	return @rtm.getTimezone
end