todo-txt 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/todo/syntax.rb +4 -1
- data/lib/todo/task.rb +49 -19
- data/spec/todo-txt/syntax_spec.rb +4 -0
- data/spec/todo-txt/task_spec.rb +5 -0
- data/todo-txt.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7d702d4739e83cb71e7663bf0feb86ab11b8d81
|
4
|
+
data.tar.gz: 107da665b03b10d335e16b582a31cfdee9ce6569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d76f95cee15a70800ecb80c96927ec5d9978e264f415c95170069b73d5388ba7b49ec6dbfe8d53252e9b7166496a5ff5a7b0e2f6c5223048ede4b757a13b22
|
7
|
+
data.tar.gz: 914f9766d4c6932d37f70f0be79e526a4487a70ffad95c377b6e461744c9d3fe7b0147f1633a9de8f6658f00ab1a7561e8d52fcc72b79e1531c859b6cb801fe4
|
data/lib/todo/syntax.rb
CHANGED
@@ -13,7 +13,9 @@ module Todo
|
|
13
13
|
# The regex used to match creation date.
|
14
14
|
CREATED_ON_PATTERN = /(?:^|-\d{2}\s|\)\s)(\d{4}-\d{2}-\d{2})\s/
|
15
15
|
|
16
|
-
|
16
|
+
COMPLETED_FLAG_PATTERN = /^x\s+/
|
17
|
+
|
18
|
+
# The regex used to match completion date.
|
17
19
|
COMPLETED_ON_PATTERN = /^x\s+(\d{4}-\d{2}-\d{2})\s+/
|
18
20
|
|
19
21
|
# The regex used to match due date.
|
@@ -30,6 +32,7 @@ module Todo
|
|
30
32
|
# @return [String] the text content of the item
|
31
33
|
def extract_item_text(line)
|
32
34
|
line.gsub(COMPLETED_ON_PATTERN, '')
|
35
|
+
.gsub(COMPLETED_FLAG_PATTERN, '')
|
33
36
|
.gsub(PRIORITY_PATTERN, '')
|
34
37
|
.gsub(CREATED_ON_PATTERN, '')
|
35
38
|
.gsub(CONTEXTS_PATTERN, '')
|
data/lib/todo/task.rb
CHANGED
@@ -260,25 +260,6 @@ module Todo
|
|
260
260
|
done? ? undo! : do!
|
261
261
|
end
|
262
262
|
|
263
|
-
# Returns this task as a string.
|
264
|
-
#
|
265
|
-
# Example:
|
266
|
-
#
|
267
|
-
# task = Todo::Task.new("(A) 2012-12-08 Task")
|
268
|
-
# task.to_s
|
269
|
-
# # => "(A) 2012-12-08 Task"
|
270
|
-
def to_s
|
271
|
-
[
|
272
|
-
done? && "x #{completed_on}",
|
273
|
-
priority && "(#{priority})",
|
274
|
-
created_on.to_s,
|
275
|
-
text,
|
276
|
-
contexts.join(' '),
|
277
|
-
projects.join(' '),
|
278
|
-
tags.map { |tag,val| "#{tag}:#{val}" }.join(' ')
|
279
|
-
].grep(String).join(' ').strip
|
280
|
-
end
|
281
|
-
|
282
263
|
# Compares the priorities of two tasks.
|
283
264
|
#
|
284
265
|
# Example:
|
@@ -305,5 +286,54 @@ module Todo
|
|
305
286
|
other.priority <=> priority
|
306
287
|
end
|
307
288
|
end
|
289
|
+
|
290
|
+
# Returns this task as a string.
|
291
|
+
#
|
292
|
+
# Example:
|
293
|
+
#
|
294
|
+
# task = Todo::Task.new("(A) 2012-12-08 Task")
|
295
|
+
# task.to_s
|
296
|
+
# # => "(A) 2012-12-08 Task"
|
297
|
+
def to_s
|
298
|
+
[
|
299
|
+
print_done_marker,
|
300
|
+
print_priority,
|
301
|
+
created_on.to_s,
|
302
|
+
text,
|
303
|
+
print_contexts,
|
304
|
+
print_projects,
|
305
|
+
print_tags
|
306
|
+
].reject { |item| !item || item.nil? || item.empty? }.join(' ')
|
307
|
+
end
|
308
|
+
|
309
|
+
private
|
310
|
+
|
311
|
+
def print_done_marker
|
312
|
+
return unless done?
|
313
|
+
|
314
|
+
if completed_on.nil?
|
315
|
+
COMPLETED_FLAG
|
316
|
+
else
|
317
|
+
"#{COMPLETED_FLAG} #{completed_on}"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
def print_priority
|
322
|
+
return unless priority
|
323
|
+
|
324
|
+
"(#{priority})"
|
325
|
+
end
|
326
|
+
|
327
|
+
def print_contexts
|
328
|
+
contexts.join(' ')
|
329
|
+
end
|
330
|
+
|
331
|
+
def print_projects
|
332
|
+
projects.join(' ')
|
333
|
+
end
|
334
|
+
|
335
|
+
def print_tags
|
336
|
+
tags.map { |tag, val| "#{tag}:#{val}" }.join(' ')
|
337
|
+
end
|
308
338
|
end
|
309
339
|
end
|
@@ -153,5 +153,9 @@ describe Todo::Syntax do
|
|
153
153
|
specify 'completed task with projects and context' do
|
154
154
|
expect(extract_item_text('x 2016-03-30 2016-03-29 something to do +experiment @work')).to eq('something to do')
|
155
155
|
end
|
156
|
+
|
157
|
+
specify 'completed task without completion date' do
|
158
|
+
expect(extract_item_text('x completed task')).to eq('completed task')
|
159
|
+
end
|
156
160
|
end
|
157
161
|
end
|
data/spec/todo-txt/task_spec.rb
CHANGED
@@ -302,6 +302,11 @@ describe Todo::Task do
|
|
302
302
|
expect(task.done?).to be true
|
303
303
|
end
|
304
304
|
|
305
|
+
it '#to_s should round-trip to identical #raw output' do
|
306
|
+
task = Todo::Task.new('x This is done!')
|
307
|
+
expect(task.to_s).to eq(task.raw)
|
308
|
+
end
|
309
|
+
|
305
310
|
after do
|
306
311
|
Todo.options.reset
|
307
312
|
end
|
data/todo-txt.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Rose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows for simple parsing of todo.txt files, as per Gina Trapani's todo.txt
|
14
14
|
project.
|