todo-jsonl 0.1.24 → 0.1.25

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 +48 -56
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f947add722dd8daa2e1c9e95b28e88ca906adb71c27af00ef251702c75c868e8
4
- data.tar.gz: ec96ca95d021e7eb4ed2ebb2e4738d08a19291e54c366873843b5c6a66108347
3
+ metadata.gz: d47bb16f60f84f6c3e55951169bdb0871f915b7a6948844897fa8a150df05456
4
+ data.tar.gz: '09600be32199c25bc946036ee947290c7c77472d00933fee39c67d9bd2dc0649'
5
5
  SHA512:
6
- metadata.gz: 5bb56460d8dd36f2643e13f0c5d4c969c4a3ebdfb887da54dabf07771ad9fbf80cbd5c115e8b058cc837aaa690ecb54850183e25d6609d4387b6335bffc0e5df
7
- data.tar.gz: 8abecd75607bc3208ddc5a73bc13cf7a1f3921a9c9275e0d067ee9c0b12c22cc7280701943c0f11d417daa1cf3cbcb3541704c2c5ec9c99ea6ada8ffe9372642
6
+ metadata.gz: 3ae62a56b667ebcb55e661d1ac64cd4c2b62db7d7d4f106c79a034ca58264d4d7c3ea20a4d262e4386806baa88d472c88dcc5a6946c4d3ca8eb01bbc3d99363e
7
+ data.tar.gz: ede2f1f9f155ce5ff5acacdd784b030c01e11f14a4ef6d85e5223663dc3a0dea5a2ab8a3eac95f498808747fa9588723d1feef36828e4657ee23cd41736aa4e0
data/bin/todo.rb CHANGED
@@ -155,7 +155,7 @@ class Todo
155
155
  * list <regex> [regex...] list tasks (only active tasks by default)
156
156
  * show <tasknumber> show all task details
157
157
  * repl enter read-eval-print loop mode
158
- * cleanup <regex> [regex...] cleanup completed tasks by regexp
158
+ * cleanup <regex> [regex...] cleanup completed tasks by regex
159
159
  * help this help screen
160
160
 
161
161
  With list command the following pre-defined regex patterns can be also used:
@@ -201,9 +201,7 @@ class Todo
201
201
  end
202
202
  end
203
203
  end
204
- if item_to_check && !tasks.has_key?(item_to_check)
205
- raise "#{item_to_check}: No such todo"
206
- end
204
+ raise "#{item_to_check}: No such todo" if item_to_check && !tasks.has_key?(item_to_check)
207
205
  tasks
208
206
  end
209
207
 
@@ -237,69 +235,67 @@ class Todo
237
235
  list
238
236
  end
239
237
 
240
- def append(item, text = '')
238
+ def update_task(item, post_action, update_function)
241
239
  tasks = load_tasks(item)
242
- tasks[item][:title] = [tasks[item][:title], text].join(' ')
240
+ update_function.call(tasks[item])
243
241
  tasks[item][:modified] = @today.strftime(DATE_FORMAT)
244
- postprocess_tags(tasks[item])
245
242
  write_tasks(tasks)
246
- list(tasks)
243
+ send(post_action, tasks) if post_action
244
+ end
245
+
246
+ def append(item, text = '')
247
+ update_task item, :list, lambda { |task|
248
+ task[:title] = [task[:title], text].join(' ')
249
+ postprocess_tags(task)
250
+ }
247
251
  end
248
252
 
249
253
  def rename(item, text)
250
- tasks = load_tasks(item)
251
- tasks[item][:title] = text
252
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
253
- postprocess_tags(tasks[item])
254
- write_tasks(tasks)
255
- list(tasks)
254
+ update_task item, :list, lambda { |task|
255
+ task[:title] = text
256
+ postprocess_tags(task)
257
+ }
256
258
  end
257
259
 
258
260
  def delete(item)
259
261
  tasks = load_tasks(item)
260
262
  tasks.delete(item)
261
263
  write_tasks(tasks)
262
- list
264
+ list(tasks)
263
265
  end
264
266
 
265
267
  def change_state(item, state, note = nil)
266
- tasks = load_tasks(item)
267
- tasks[item][:state] = state
268
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
269
- if !note.nil? && !note.empty?
270
- tasks[item][:note] ||= []
271
- tasks[item][:note].push(note)
272
- end
273
- write_tasks(tasks)
274
- list(tasks)
268
+ update_task item, :list, lambda { |task|
269
+ task[:state] = state
270
+ if !note.nil? && !note.empty?
271
+ task[:note] ||= []
272
+ task[:note].push(note)
273
+ end
274
+ }
275
275
  end
276
276
 
277
277
  def set_priority(item, note = nil)
278
- tasks = load_tasks(item)
279
- tasks[item][:priority] = !tasks[item][:priority]
280
- tasks[item].delete(:priority) if !tasks[item][:priority]
281
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
282
- if !note.nil? && !note.empty?
283
- tasks[item][:note] ||= []
284
- tasks[item][:note].push(note)
285
- end
286
- write_tasks(tasks)
287
- list(tasks)
278
+ update_task item, :list, lambda { |task|
279
+ task[:priority] = !task[:priority]
280
+ task.delete(:priority) if !task[:priority]
281
+ if !note.nil? && !note.empty?
282
+ task[:note] ||= []
283
+ task[:note].push(note)
284
+ end
285
+ }
288
286
  end
289
287
 
290
288
  def due_date(item, date = '')
291
- tasks = load_tasks(item)
292
- tasks[item][:due] = convert_due_date(date)
293
- tasks[item].delete(:due) if tasks[item][:due].nil?
294
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
295
- write_tasks(tasks)
296
- list(tasks)
289
+ update_task item, :list, lambda { |task|
290
+ task[:due] = convert_due_date(date)
291
+ task.delete(:due) if task[:due].nil?
292
+ }
297
293
  end
298
294
 
299
295
  def list(tasks = nil, patterns = nil)
300
296
  tasks = tasks || load_tasks
301
297
  task_indent = [tasks.keys.max.to_s.size, 4].max
302
- patterns = patterns.nil? || patterns.empty? ? [@queries[':active']] : patterns
298
+ patterns = patterns.nil? || patterns.empty? ? [':active'] : patterns
303
299
  items = filter_tasks(tasks, patterns)
304
300
  items = items.sort_by do |num, task|
305
301
  [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
@@ -330,24 +326,20 @@ class Todo
330
326
  end
331
327
 
332
328
  def add_note(item, text)
333
- tasks = load_tasks(item)
334
- tasks[item][:note] ||= []
335
- tasks[item][:note].push(text)
336
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
337
- write_tasks(tasks)
338
- show(item)
329
+ update_task item, :show, lambda { |task|
330
+ task[:note] ||= []
331
+ task[:note].push(text)
332
+ }
339
333
  end
340
334
 
341
335
  def delete_note(item)
342
- tasks = load_tasks(item)
343
- tasks[item].delete(:note)
344
- tasks[item][:modified] = @today.strftime(DATE_FORMAT)
345
- write_tasks(tasks)
346
- show(item)
336
+ update_task item, :show, lambda { |task|
337
+ task.delete(:note)
338
+ }
347
339
  end
348
340
 
349
- def show(item)
350
- tasks = load_tasks(item)
341
+ def show(item, tasks = nil)
342
+ tasks = tasks || load_tasks(item)
351
343
  tasks[item].each do |key, value|
352
344
  val = value.kind_of?(Array) ? "\n" + value.join("\n") : value
353
345
  puts "#{colorize(key.to_s.rjust(10, ' ') + ':', :cyan)} #{val}"
@@ -369,7 +361,7 @@ class Todo
369
361
 
370
362
  def cleanup(patterns)
371
363
  tasks = load_tasks
372
- patterns = [@queries[':done']] + patterns.to_a
364
+ patterns = [':done'] + patterns.to_a
373
365
  items = filter_tasks(tasks, patterns)
374
366
  items.keys.each do |num| tasks.delete(num) end
375
367
  write_tasks(tasks)
@@ -393,7 +385,7 @@ class Todo
393
385
  "\e[#{COLOR_CODES[color]}m#{text}\e[0m"
394
386
  end
395
387
 
396
- def convert_due_date(date = '')
388
+ def convert_due_date(date)
397
389
  due = nil
398
390
  day_index = @due_date_days.index(date.to_s.downcase) ||
399
391
  DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
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.24
4
+ version: 0.1.25
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-05 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: