todo-jsonl 0.1.17 → 0.1.22

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/todo.rb +36 -17
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66be9ecc38d960f5207cc45621ea59daf90513823b96082f2d27c7062742c270
4
- data.tar.gz: 77fdb42c6675a963a1360e9375e03b0b0d4c7fa2fca1d0721f3337da2276685c
3
+ metadata.gz: 1c785fb535af9ce8e4aa7104e57c66133f6bf201ffb6bc28372d2b386decc4e1
4
+ data.tar.gz: 6ce70f3e7160c997921bcdbacb442d9e04330019265e60ad4accab1a1cf386ab
5
5
  SHA512:
6
- metadata.gz: af9f2d586cf93b6642e3f1f99f62e2460e2bbfe1d8a5c659c4835e4c84421733674ce58961581129c75d9b334aac581ae2f92a56f7022f2cdffdfb7f55779806
7
- data.tar.gz: 91fe599991ade9a1eccc8fae0ef841b1845d1f47b98bef6f9bc98314120552a86cae1b6c411c715f79525557d8170c5d311f140c26c87fc234990c719a00949e
6
+ metadata.gz: 18781618d8824776f157cce55015bdd49cd4d68791a6c4f24d86d9f66acb331ef4f2e2b22b1f8577e1f92f32bb232dbb061afa66f8f59aa7bc07bb0bc6d29083
7
+ data.tar.gz: e0544156459535841c4be51378071f40dda66f945733acf927328930699d0bd3d5b111996ea73cfd5f89f13418617a037d5e418f255093ac95f2d2689ce49da5
data/bin/todo.rb CHANGED
@@ -115,9 +115,14 @@ class Todo
115
115
  raise action + ' command requires exactly one parameter' if args.length != 1
116
116
  show(args.first.to_i)
117
117
  when 'help'
118
+ raise action + ' command has no parameters' if args.length > 0
118
119
  puts usage
119
120
  when 'repl'
121
+ raise action + ' command has no parameters' if args.length > 0
120
122
  start_repl
123
+ when 'cleanup'
124
+ raise action + ' command requires at least one parameter' if args.nil? || args.empty?
125
+ cleanup(args)
121
126
  else
122
127
  list(nil, arguments)
123
128
  end
@@ -150,6 +155,7 @@ class Todo
150
155
  * list <regex> [regex...] list tasks (only active tasks by default)
151
156
  * show <tasknumber> show all task details
152
157
  * repl enter read-eval-print loop mode
158
+ * cleanup <regex> [regex...] cleanup completed tasks by regexp
153
159
  * help this help screen
154
160
 
155
161
  With list command the following pre-defined regex patterns can be also used:
@@ -165,8 +171,8 @@ class Todo
165
171
  end
166
172
 
167
173
  def setup
168
- @today = Time.now
169
- next_7_days = (0..6).map do |day| (@today.to_date + day) end
174
+ @today = Date.today
175
+ next_7_days = (0..6).map do |day| @today + day end
170
176
  @due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
171
177
  due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
172
178
 
@@ -281,7 +287,7 @@ class Todo
281
287
  list(tasks)
282
288
  end
283
289
 
284
- def due_date(item, date = '', task = nil)
290
+ def due_date(item, date = '')
285
291
  tasks = load_tasks(item)
286
292
  tasks[item][:due] = convert_due_date(date)
287
293
  tasks[item].delete(:due) if tasks[item][:due].nil?
@@ -291,18 +297,10 @@ class Todo
291
297
  end
292
298
 
293
299
  def list(tasks = nil, patterns = nil)
294
- items = {}
295
300
  tasks = tasks || load_tasks
296
301
  task_indent = [tasks.keys.max.to_s.size, 4].max
297
302
  patterns = patterns.nil? || patterns.empty? ? [@queries[':active']] : patterns
298
- tasks.each do |num, task|
299
- normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
300
- match = true
301
- patterns.each do |pattern|
302
- match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
303
- end
304
- items[num] = task if match
305
- end
303
+ items = filter_tasks(tasks, patterns)
306
304
  items = items.sort_by do |num, task|
307
305
  [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
308
306
  end
@@ -316,7 +314,7 @@ class Todo
316
314
  priority_flag = task[:priority] ? colorize(PRIORITY_FLAG, :red) : ' '
317
315
  due_date = ''
318
316
  if task[:due] && state != 'done'
319
- date_diff = (Date.parse(task[:due]) - @today.to_date).to_i
317
+ date_diff = (Date.strptime(task[:due], DATE_FORMAT) - @today).to_i
320
318
  if date_diff < 0
321
319
  due_date = colorize("(#{date_diff.abs}d overdue)", :red)
322
320
  elsif date_diff == 0 || date_diff == 1
@@ -369,6 +367,28 @@ class Todo
369
367
  end
370
368
  end
371
369
 
370
+ def cleanup(patterns)
371
+ tasks = load_tasks
372
+ patterns = [@queries[':done']] + patterns.to_a
373
+ items = filter_tasks(tasks, patterns)
374
+ items.keys.each do |num| tasks.delete(num) end
375
+ write_tasks(tasks)
376
+ puts "deleted #{items.size} todo(s)"
377
+ end
378
+
379
+ def filter_tasks(tasks, patterns)
380
+ items = {}
381
+ tasks.each do |num, task|
382
+ normalized_task = "state=#{task[:state]} due=#{task[:due]} #{task[:title]}"
383
+ match = true
384
+ patterns.each do |pattern|
385
+ match = false unless /#{@queries[pattern] || pattern}/ix.match(normalized_task)
386
+ end
387
+ items[num] = task if match
388
+ end
389
+ return items
390
+ end
391
+
372
392
  def colorize(text, color)
373
393
  "\e[#{COLOR_CODES[color]}m#{text}\e[0m"
374
394
  end
@@ -379,14 +399,13 @@ class Todo
379
399
  DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
380
400
  @due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
381
401
  if day_index
382
- due = (@today.to_date + day_index).strftime(DATE_FORMAT)
402
+ due = (@today + day_index).strftime(DATE_FORMAT)
383
403
  else
384
- due = date.nil? || date.empty? ? nil : Date.parse(date).strftime(DATE_FORMAT)
404
+ due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
385
405
  end
386
406
  return due
387
407
  end
388
408
 
389
409
  end
390
410
 
391
- todo = Todo.new
392
- todo.execute(ARGV)
411
+ Todo.new.execute(ARGV)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo-jsonl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabor Bata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: