Class: CommandLineInterface

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

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, token) ⇒ CommandLineInterface

Returns a new instance of CommandLineInterface.



135
136
137
# File 'lib/thartmx.rb', line 135

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

Instance Method Details

#addObject



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

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

#color(s, t) ⇒ Object



184
185
186
187
188
189
190
191
192
193
# File 'lib/thartmx.rb', line 184

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



207
208
209
210
211
212
213
# File 'lib/thartmx.rb', line 207

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

#firstObject



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

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



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/thartmx.rb', line 256

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



199
200
201
202
203
204
205
# File 'lib/thartmx.rb', line 199

def lists
	l = @rtm.lists

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

#postponeObject



215
216
217
218
219
220
221
# File 'lib/thartmx.rb', line 215

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

#tasksObject



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

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



223
224
225
# File 'lib/thartmx.rb', line 223

def tz
	return @rtm.getTimezone
end