thartm 0.0.23 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bin/rrtm +2 -2
  3. data/lib/thartm.rb +62 -22
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.23
1
+ 0.1.1
data/bin/rrtm CHANGED
@@ -31,8 +31,8 @@ cli = CommandLineInterface.new(@@config['key'],@@config['secret'],@@config['toke
31
31
  if ARGV[0]
32
32
  begin
33
33
  cli.send ARGV[0]
34
- rescue
35
- puts "command #{ARGV[0]} is not available"
34
+ rescue Exception => e
35
+ puts e, "command #{ARGV[0]} is not available"
36
36
  cli.help
37
37
  end
38
38
  else
data/lib/thartm.rb CHANGED
@@ -29,7 +29,17 @@ class Rrtm
29
29
  end
30
30
  return allTaskList
31
31
  end
32
-
32
+
33
+ def findList(name)
34
+ flist = ''
35
+ name.chomp!
36
+ @lists.each do |k,v|
37
+ if v[:name] == name
38
+ flist = v[:id]
39
+ end
40
+ end
41
+ return flist
42
+ end
33
43
  def lists
34
44
  lists = @rtm.lists.getList
35
45
  end
@@ -44,12 +54,12 @@ class Rrtm
44
54
  end
45
55
 
46
56
 
47
- def addTask(text, * args )
48
- if args.length == 1
49
- listname = args[0]
57
+ def addTask(name)
58
+ if name =~ /^(@(\w|\s)+@)/
59
+ listname = name.match(/^(@(\w|\s)+@)/)[0][1..-2]
60
+ name.sub!(/^(@(\w|\s)+@)/,'')
50
61
  end
51
-
52
- listid = 0
62
+ listid = allTaskList
53
63
  if listname
54
64
  @lists.each do |k,v|
55
65
  if v[:name].match(listname)
@@ -58,11 +68,7 @@ class Rrtm
58
68
  end
59
69
  end
60
70
 
61
- if listid != 0
62
- @rtm.tasks.add :timeline => @timeline, :name => text, :parse => '1', :list_id => listid
63
- else
64
- @rtm.tasks.add :timeline => @timeline, :name => text, :parse => '1'
65
- end
71
+ @rtm.tasks.add :timeline => @timeline, :name => name, :parse => '1', :list_id => listid
66
72
  end
67
73
 
68
74
  def findTask(id)
@@ -104,11 +110,26 @@ class CommandLineInterface
104
110
 
105
111
  def tasks
106
112
  t = Array.new
107
- tasks = @rtm.tasksAllTaskList
113
+ if ARGV[1]
114
+ l = @rtm.findList(ARGV[1..-1].join(" "))
115
+ begin
116
+ tasks = @rtm.tasks :list_id => l
117
+ rescue Exception => e
118
+ puts e,"list not found"
119
+ return ''
120
+ end
121
+ else
122
+
123
+ tasks = @rtm.tasksAllTaskList
108
124
 
125
+ end
109
126
  tasks.each do |key,val|
110
- val.each do |k,v|
111
- t.push(v) unless v.complete? # do not add c ompleted tasks
127
+ if val.class == RememberTheMilkHash
128
+ val.each do |k,v|
129
+ t.push(v) unless v.complete? # do not add c ompleted tasks
130
+ end
131
+ elsif val.class == RememberTheMilkTask
132
+ t.push(val) unless val.complete? # do not add c ompleted tasks
112
133
  end
113
134
  end
114
135
 
@@ -126,15 +147,25 @@ class CommandLineInterface
126
147
  end
127
148
 
128
149
  # compose string result
129
- s = ''
130
150
  t.each do |tt|
131
- s += tt[:id] + ": " + tt[:name].to_s + " -- " + tt.due.to_s + "\n"
151
+ s = tt[:id] + ": " + tt[:name].to_s + " -- " + tt.due.to_s + "\n"
152
+ color(s,tt)
132
153
  end
133
- puts s
134
154
  end
135
155
 
156
+ def color(s,t)
157
+ p = case t[:task][0][:priority]
158
+ when 'N' then printf("\e[0m%s \e[0m",s)
159
+ when '1' then printf("\e[31;40m%s \e[0m",s)
160
+ when '2' then printf("\e[32;40m%s \e[0m",s)
161
+ when '3' then printf("\e[32;40m%s \e[0m",s)
162
+ else puts "err"
163
+ end
164
+
165
+ end
166
+
136
167
  def add
137
- @rtm.addTask(ARGV[1], ARGV[2] )
168
+ @rtm.addTask(ARGV[1..-1].join(" "))
138
169
  end
139
170
 
140
171
  def lists
@@ -146,11 +177,19 @@ class CommandLineInterface
146
177
  end
147
178
 
148
179
  def complete
180
+ begin
149
181
  @rtm.completeTask(ARGV[1])
182
+ rescue
183
+ p "invalid task id"
184
+ end
150
185
  end
151
186
 
152
187
  def postpone
188
+ begin
153
189
  @rtm.postpone(ARGV[1])
190
+ rescue
191
+ p "invalid task id"
192
+ end
154
193
  end
155
194
 
156
195
  def tz
@@ -193,10 +232,11 @@ usage rrtm <command> <params>
193
232
 
194
233
  help: print this help and exits
195
234
  lists: show available tasks lists
196
- tasks: show not completed tasks
197
- add name [lists name]: adds a task to the lists
198
- complete id: mark task with id "id" as completed
199
- postpone id: postpone task by one day
235
+ tasks [list name]: show not completed tasks
236
+ add <name>: name can be a task or in the form @list name@ task
237
+ add "<name>" : input is better parsed within quotes: task #Listname !priority_value(1..3)
238
+ complete <id>: mark task with id "id" as completed
239
+ postpone <id>: postpone task by one day
200
240
  first: show first uncompleted task
201
241
  '
202
242
  puts s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thartm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tha
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-08 00:00:00 +02:00
12
+ date: 2010-06-10 00:00:00 +02:00
13
13
  default_executable: rrtm
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency