tot 0.0.2 → 0.0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/lib/tot/version.rb +1 -1
  3. data/lib/tot.rb +84 -54
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTUwOTA3NmQxYmRlMWVmYTkzZmYxNmZlOTg3ZTI2Nzg3NzM0NGEwZQ==
4
+ YmEwNjViNTUxZTgxNDNkYjk5NGMzOGNiNzlkMTcwNjBlYTU2ZWI5MQ==
5
5
  data.tar.gz: !binary |-
6
- NGUxMDhiNDZkNDY3YjhiODg4ZWEzN2Q2NGM2MzY5NjU5MzMwZTU3OQ==
6
+ OWIwMDI5MGY0YzZjOWE2YjU1YzAzZDBjMTBhZmJjOGJjYjc4M2Q3NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjU0NWNlZTJiYTM3MTRmNDQwMjYwYTkzM2NiY2Y1MWI1YmZiNzMwN2FhZTJh
10
- MjdkM2VlOWM3MDI1OWQ5MWJjYTI1NzlhYTM3MjE5NzRiMGRmYTEyNWVmMGZl
11
- ZDYzNmUwOWVhNjQ3OGM3OTdlMDg5YTNjOWQ1NGY4MDlkNjhkY2Q=
9
+ MjY4YWNhNDRjN2ZmZTk1MmQxMTQzYmM4YjMwNmJhYjg0M2MyNWVkMDE1NzMy
10
+ OWM3MWJiZmY0OWNlMDgwNTVmZDk5NWJhZWZlODNiZTgwZDQ1NjY2MGE5MWI3
11
+ M2RhYTQzZjI0ZGQ1OTA0NmM0ZWQxODEyYWFmOWY4MTlmMDRiN2I=
12
12
  data.tar.gz: !binary |-
13
- ODFlZGU1NmVkYmNjYWI2ZDZiYjIyNGY4MGQ0M2ZhZTNmNmY3OGQ2NGVmOWU4
14
- YzE1NTNmNTdmMGJjMjM1OWEzMTNjYzU1NDkxZjI2OGY1M2U3NzU2NzU4NGZm
15
- OGZlZGEzOWI2YjM0NzBlN2MxNzQyNjNhZmZmYzVmNDhjODllNTc=
13
+ MWNiOGIzZGQ5ZjE2OThkMzJjMzg0MTZjZGY4MGVmM2RlYjNhNTFjM2QzNTA3
14
+ ZjYzZjVkOTBjN2NkZTg4YjA4ZjQ2MjE3ZDdhMGE5Y2I5OTA5NWEyNTdlYWUx
15
+ NDE1NmVjYWMyNTZlOTJmNWM0YTdiZDQyZGEyY2YzNGJkYmNhNDg=
data/lib/tot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tot
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.2.1"
3
3
  end
data/lib/tot.rb CHANGED
@@ -35,7 +35,12 @@ module Tot
35
35
  @tasks = YAML.load_file(todo_path).sort_by{|i| i['date']}
36
36
  end
37
37
 
38
- def dump
38
+ def refresh
39
+ load_file
40
+ self
41
+ end
42
+
43
+ def save
39
44
  #File.open(Config.todo_path,'w'){|file| file.puts todos.ya2yaml} #YAML.dump(todos, file)}
40
45
  # ya2yamlだとhashの順番が変わる
41
46
  File.open(Config.todo_path,'w'){|file| YAML.dump(@tasks, file)}
@@ -43,13 +48,10 @@ module Tot
43
48
 
44
49
  def add(new_todo)
45
50
  @tasks.push new_todo
46
- dump
47
51
  end
48
52
 
49
53
  def delete(at)
50
- @tasks = load_file
51
54
  @tasks.delete_at(at)
52
- dump
53
55
  end
54
56
 
55
57
  def each
@@ -153,18 +155,26 @@ module Tot
153
155
  @todo_manager = TodoManager.new
154
156
  end
155
157
 
156
- desc 'list' , 'list up your todo'
157
- method_option :tag, :type => :array
158
+ desc 'list' , 'list up your todo' #{{{
159
+ method_option :tag, :type => :array, :aliases => "-t"
160
+ method_option :filter, :type => :array, :aliases => "-f"
158
161
  def list
159
162
  if options['tag']
160
163
  @todo_manager.find_all! do |todo|
161
164
  options[:tag].all?{|i| todo['tag'].include? i}
162
165
  end
166
+ elsif options['filter']
167
+ @todo_manager.find_all! do |todo|
168
+ options['filter'].all?{|i|
169
+ re = Regexp.new(i,Regexp::IGNORECASE)
170
+ re.match(todo['title'])
171
+ }
172
+ end
163
173
  end
164
174
  @todo_manager.print_color(false)
165
- end
175
+ end #}}}
166
176
 
167
- desc 'add' , 'add a task'
177
+ desc 'add' , 'add a task' #{{{
168
178
  def add
169
179
  new_todo = {}
170
180
  new_todo['title'] = Readline.readline('title> ', true).chomp('\n')
@@ -180,73 +190,93 @@ module Tot
180
190
  print new_todo['text']
181
191
  File.delete tmpfile
182
192
  @todo_manager.add new_todo
183
- end
193
+ @todo_manager.save
194
+ end #}}}
184
195
 
185
- desc 'delete', 'delete a task'
196
+ desc 'delete', 'delete a task' #{{{
186
197
  def delete
187
198
  @todo_manager.print_color(true)
188
199
  @todo_manager.delete_at Readline.readline('Which Task?> ',false).chomp('\n').to_i
189
- @todo_manager.dump
190
- end
200
+ @todo_manager.save
201
+ end #}}}
191
202
 
192
- desc 'show TITLE', <<-EOF
203
+ desc 'show', <<-EOF #{{{
193
204
  show the detail of a task.
194
205
  TITLE does not need to be complete.
195
206
  EOF
196
- def show(title)
197
- reg = Regexp.new(title,Regexp::IGNORECASE)
198
- todos = @todo_manager.find_all{|item| reg.match(item['title'])}
207
+ method_option :filter, :type => :array, :aliases => "-f",:default => nil
208
+ def show
209
+ reg = nil
210
+ if options['filter']
211
+ reg = Regexp.new(options['filter'].join('.*'),Regexp::IGNORECASE)
212
+ else
213
+ reg = /.*/
214
+ end
215
+ todo = nil
216
+ todos = @todo_manager.find_all!{|item| reg.match(item['title'])}
199
217
  if todos.size == 0
200
218
  puts 'No matched task.'
219
+ return
201
220
  elsif todos.size > 1
202
- puts 'Several tasks matched.'
221
+ @todo_manager.print_color(true)
222
+ todo = todos[Readline.readline('Which Task?> ',false).chomp('\n').to_i]
203
223
  else
204
- todo = todos[0]
205
- puts 'Title: ' + todo['title']
206
- puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
207
- puts
208
- print todo['text']
224
+ todo = todos.first
209
225
  end
226
+ puts 'Title: ' + todo['title']
227
+ puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
228
+ puts
229
+ print todo['text']
210
230
 
211
- end
231
+ end #}}}
212
232
 
213
- desc 'edit TITLE', 'edit a task'
233
+ desc 'edit', 'edit a task' #{{{
214
234
  method_options :text => :boolean, :title => :boolean, :date => :boolean, :tag => :boolean
215
- def edit(title)
216
- reg = Regexp.new(title,Regexp::IGNORECASE)
217
- todos = @todo_manager.find_all{|item| reg.match(item['title'])}
235
+ method_option :filter, :type => :array, :aliases => "-f",:default => nil
236
+ def edit
237
+ reg = nil
238
+ if options['filter']
239
+ reg = Regexp.new(options['filter'].join('.*'),Regexp::IGNORECASE)
240
+ else
241
+ reg = /.*/
242
+ end
243
+ todo = nil
244
+ todos = @todo_manager.find_all!{|item| reg.match(item['title'])}
218
245
  if todos.size == 0
219
246
  puts 'No matched task.'
247
+ return
220
248
  elsif todos.size > 1
221
- puts todos.size.to_s + ' tasks matched.'
249
+ @todo_manager.print_color(true)
250
+ todo = todos[Readline.readline('Which Task?> ',false).chomp('\n').to_i]
222
251
  else
223
- todo = todos[0]
224
- old_title = todo['title']
225
- if options['title']
226
- todo['title'] = Readline.readline('New Title> ').chomp('\n')
227
- elsif options['date']
228
- todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
229
- elsif options['tag']
230
- todo['tag'] = Readline.readline("tag (old_value: #{todo['tag'].join(' ')})> ", true)
231
- .chomp('\n').split(' ')
232
- else
233
- tmpfile = "/tmp/tot.markdown"
234
- File.open(tmpfile,'w'){|file| file.write todo['text']}
235
- system([ENV['EDITOR'],tmpfile].join(' '))
236
- todo['text'] = File.readlines(tmpfile).join
237
- File.delete tmpfile
238
- end
252
+ todo = todos.first
253
+ end
239
254
 
240
- puts 'Title: ' + todo['title']
241
- puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
242
- puts 'Tags: ' + todo['tag'].to_s
243
- puts
244
- print todo['text']
245
- @todo_manager.delete_at(@todo_manager.find_index{|obj| obj['title'] == old_title})
246
- @todo_manager.add todo
255
+ old_title = todo['title']
256
+ if options['title']
257
+ todo['title'] = Readline.readline('New Title> ').chomp('\n')
258
+ elsif options['date']
259
+ todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s)
260
+ elsif options['tag']
261
+ todo['tag'] = Readline.readline("tag (old_value: #{todo['tag'].join(' ')})> ", true)
262
+ .chomp('\n').split(' ')
263
+ else
264
+ tmpfile = "/tmp/tot.markdown"
265
+ File.open(tmpfile,'w'){|file| file.write todo['text']}
266
+ system([ENV['EDITOR'],tmpfile].join(' '))
267
+ todo['text'] = File.readlines(tmpfile).join
268
+ File.delete tmpfile
247
269
  end
248
-
249
- end
270
+
271
+ puts 'Title: ' + todo['title']
272
+ puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M")
273
+ puts 'Tags: ' + todo['tag'].to_s
274
+ puts
275
+ print todo['text']
276
+ @todo_manager.delete_at(@todo_manager.find_index{|obj| obj['title'] == old_title})
277
+ @todo_manager.add todo
278
+ @todo_manager.save
279
+ end #}}}
280
+
250
281
  end
251
282
  end
252
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shohei Fujii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler