todo-jsonl 0.1.32 → 1.0.3

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 +38 -37
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70b3b87cee25e9b7f3b98d8c4fabfa9314953ab473fa845af8d5ac3865416bf3
4
- data.tar.gz: fc60551fd9ad077cbb794c91dc94595cc8969eaeede825d42bf425b1654113f4
3
+ metadata.gz: 40ddf723c9cd6d6f2bbfd6a2e79d793b2e4a9e566ab03decb98ffa2b26ab7aae
4
+ data.tar.gz: f503bf830367cca971c40625adbf5d2ac73f75055c0ec1aa7d5d76676b2a8dce
5
5
  SHA512:
6
- metadata.gz: ee42c84380d64142ba3f64a9ea7deee06f874f3a9f6a9ac4142fc834a14b8f66732118ca1072d43bf484674971c37944053deff4fed89e797527b7a83fa1ff25
7
- data.tar.gz: f79bc0d5be7041e6efcc25f1f88afa43eecf10c382d7353f6b3fa55d6752756b767152b52ab694b5999eda0bbce58ed60ba36b520b09c16309b0ee06f36f82f5
6
+ metadata.gz: e6938c3a54128c70a606db10c737a482bf9192d2f6dfa8f01c66e1805ec3af1f7da1ddba7f99769015e29349c63f153eb409fea3b68db5f68c8629ac99113dff
7
+ data.tar.gz: b63dd1f3e0f93b1ef2677040695b75d9b4ed373cda2243a0e08f60a5f4e4f77187f918d97ee4a54ccfb20467d58980c016af67ceec8e07ad69e8ba69dce95fe6
data/bin/todo.rb CHANGED
@@ -29,7 +29,6 @@ require 'json'
29
29
  require 'date'
30
30
 
31
31
  class Todo
32
-
33
32
  COLOR_CODES = {
34
33
  black: 30,
35
34
  red: 31,
@@ -70,7 +69,7 @@ class Todo
70
69
  DUE_DATE_TAG_PATTERN = /(^| )due:([a-zA-Z0-9-]+)/
71
70
  CONTEXT_TAG_PATTERN = /(^| )[@+][\w-]+/
72
71
  PRIORITY_FLAG = '*'
73
- TODO_FILE = "#{ENV['HOME']}/todo.jsonl"
72
+ TODO_FILE = File.join(Dir.home, 'todo.jsonl')
74
73
 
75
74
  def execute(arguments)
76
75
  begin
@@ -127,7 +126,7 @@ class Todo
127
126
  else
128
127
  list(nil, arguments)
129
128
  end
130
- rescue => error
129
+ rescue StandardError => error
131
130
  puts "#{colorize('ERROR:', :red)} #{error}"
132
131
  end
133
132
  self
@@ -160,13 +159,14 @@ class Todo
160
159
  * cleanup <regex> [regex...] cleanup completed tasks by regex
161
160
  * help this help screen
162
161
 
163
- With list command the following pre-defined regex patterns can be also used:
164
- #{@queries.keys.join(', ')}
162
+ With list command the following pre-defined queries can be also used:
163
+ #{@queries.keys.each_with_index.map { |k, i| (i == 8 ? "\n" : '') + k }.join(', ')}
165
164
 
166
165
  Due dates can be also added via tags in task title: "due:YYYY-MM-DD"
166
+ In addition to formatted dates, you can use date synonyms:
167
+ "due:today", "due:tomorrow", and day names e.g. "due:monday" or "due:tue"
167
168
 
168
- Legend:
169
- #{STATES.select { |k, v| k != 'default' }.map { |k, v| "#{k} #{v}" }.join(', ') }, priority #{PRIORITY_FLAG}
169
+ Legend: #{STATES.select { |k, v| k != 'default' }.map { |k, v| "#{k} #{v}" }.join(', ') }, priority #{PRIORITY_FLAG}
170
170
 
171
171
  Todo file: #{TODO_FILE}
172
172
  USAGE
@@ -174,20 +174,23 @@ class Todo
174
174
 
175
175
  def setup
176
176
  @today = Date.today
177
- next_7_days = (0..6).map do |day| @today + day end
178
- @due_date_days = next_7_days.map do |day| day.strftime('%A').downcase end
179
- due_dates_for_queries = next_7_days.map do |day| day.strftime(DATE_FORMAT) end
180
-
177
+ next_7_days = (0..6).map { |day| @today + day }
178
+ @due_date_days = next_7_days.map { |day| day.strftime('%A').downcase }
179
+ due_dates_for_queries = next_7_days.map { |day| day.strftime(DATE_FORMAT) }
181
180
  @queries = {
182
- ':active' => lambda do |task| /(new|started|blocked)/.match(task[:state]) end,
183
- ':done' => lambda do |task| 'done' == task[:state] end,
184
- ':blocked' => lambda do |task| 'blocked' == task[:state] end,
185
- ':started' => lambda do |task| 'started' == task[:state] end,
186
- ':new' => lambda do |task| 'new' == task[:state] end,
187
- ':all' => lambda do |task| /\w+/.match(task[:state]) end,
188
- ':today' => lambda do |task| due_dates_for_queries[0] == task[:due] end,
189
- ':tomorrow' => lambda do |task| due_dates_for_queries[1] == task[:due] end,
190
- ':next7days' => lambda do |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) end
181
+ ':active' => lambda { |task| /(new|started|blocked)/.match(task[:state]) },
182
+ ':done' => lambda { |task| 'done' == task[:state] },
183
+ ':blocked' => lambda { |task| 'blocked' == task[:state] },
184
+ ':started' => lambda { |task| 'started' == task[:state] },
185
+ ':new' => lambda { |task| 'new' == task[:state] },
186
+ ':all' => lambda { |task| /\w+/.match(task[:state]) },
187
+ ':priority' => lambda { |task| task[:priority] },
188
+ ':note' => lambda { |task| task[:note] && !task[:note].empty? },
189
+ ':today' => lambda { |task| due_dates_for_queries[0] == task[:due] },
190
+ ':tomorrow' => lambda { |task| due_dates_for_queries[1] == task[:due] },
191
+ ':next7days' => lambda { |task| /(#{due_dates_for_queries.join('|')})/.match(task[:due]) },
192
+ ':overdue' => lambda { |task| task[:due] && task[:due] < due_dates_for_queries[0] },
193
+ ':due' => lambda { |task| task[:due] }
191
194
  }
192
195
  end
193
196
 
@@ -226,8 +229,8 @@ class Todo
226
229
 
227
230
  def add(text)
228
231
  task = {
229
- state: 'new',
230
- title: text,
232
+ state: 'new',
233
+ title: text,
231
234
  modified: @today.strftime(DATE_FORMAT)
232
235
  }
233
236
  postprocess_tags(task)
@@ -303,7 +306,12 @@ class Todo
303
306
  patterns ||= []
304
307
  patterns += [':active'] if (patterns & [':active', ':done', ':blocked', ':started', ':new', ':all']).empty?
305
308
  items = filter_tasks(tasks, patterns).sort_by do |num, task|
306
- [task[:priority] && task[:state] != 'done' ? 0 : 1, ORDER[task[:state] || 'default'], task[:due] || 'n/a', num]
309
+ [
310
+ task[:priority] && task[:state] != 'done' ? 0 : 1,
311
+ ORDER[task[:state] || 'default'],
312
+ task[:state] != 'done' ? task[:due] || 'n/a' : task[:modified],
313
+ num
314
+ ]
307
315
  end
308
316
  items.each do |num, task|
309
317
  state = task[:state] || 'default'
@@ -367,20 +375,18 @@ class Todo
367
375
  tasks = load_tasks
368
376
  patterns = [':done'] + patterns.to_a
369
377
  items = filter_tasks(tasks, patterns)
370
- items.each_key do |num| tasks.delete(num) end
378
+ items.each_key { |num| tasks.delete(num) }
371
379
  write_tasks(tasks)
372
380
  puts "Deleted #{items.size} todo(s)"
373
381
  end
374
382
 
375
383
  def filter_tasks(tasks, patterns)
376
- items = {}
377
- tasks.each do |num, task|
378
- match = patterns.uniq.all? do |pattern|
384
+ patterns = patterns.uniq
385
+ tasks.select do |num, task|
386
+ patterns.all? do |pattern|
379
387
  @queries[pattern] ? @queries[pattern].call(task) : /#{pattern}/ix.match(task[:title])
380
388
  end
381
- items[num] = task if match
382
389
  end
383
- return items
384
390
  end
385
391
 
386
392
  def colorize(text, color)
@@ -388,16 +394,11 @@ class Todo
388
394
  end
389
395
 
390
396
  def convert_due_date(date)
391
- due = nil
392
397
  day_index = @due_date_days.index(date.to_s.downcase) ||
393
398
  DUE_DATE_DAYS_SIMPLE.index(date.to_s.downcase) ||
394
- @due_date_days.map do |day| day[0..2] end.index(date.to_s.downcase)
395
- if day_index
396
- due = (@today + day_index).strftime(DATE_FORMAT)
397
- else
398
- due = date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
399
- end
400
- return due
399
+ @due_date_days.map { |day| day[0..2] }.index(date.to_s.downcase)
400
+ return (@today + day_index).strftime(DATE_FORMAT) if day_index
401
+ date.nil? || date.empty? ? nil : Date.strptime(date, DATE_FORMAT).strftime(DATE_FORMAT)
401
402
  end
402
403
  end
403
404
 
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.32
4
+ version: 1.0.3
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-17 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: