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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e6194a6c093149543776903fec449488ff35e12
4
- data.tar.gz: 1ff563eca42c38f95a55eda4732f4c43005a2079
3
+ metadata.gz: c7d702d4739e83cb71e7663bf0feb86ab11b8d81
4
+ data.tar.gz: 107da665b03b10d335e16b582a31cfdee9ce6569
5
5
  SHA512:
6
- metadata.gz: 0d614c4914dfc5e7e84addd6185f79c52270a4196003be1bef3f88452063e4d549062855d3229b92413dfe1f9b0f896ff6fe12cc7b64786767300aa9ff430a56
7
- data.tar.gz: 0b8307a2946e632a5a68fb1b03b1df5d2fcbf56317087ebac52e7d3317b742ba8e9a5f7e31de9ff8723683e940a50d2d11bd39e58a4b806265a05180f6fa123e
6
+ metadata.gz: b1d76f95cee15a70800ecb80c96927ec5d9978e264f415c95170069b73d5388ba7b49ec6dbfe8d53252e9b7166496a5ff5a7b0e2f6c5223048ede4b757a13b22
7
+ data.tar.gz: 914f9766d4c6932d37f70f0be79e526a4487a70ffad95c377b6e461744c9d3fe7b0147f1633a9de8f6658f00ab1a7561e8d52fcc72b79e1531c859b6cb801fe4
@@ -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
- # The regex used to match completion.
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, '')
@@ -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
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'todo-txt'
3
- s.version = '0.10'
3
+ s.version = '0.11'
4
4
  s.authors = ['Sam Rose']
5
5
  s.email = 'samwho@lbak.co.uk'
6
6
  s.summary = 'A client library for parsing todo.txt files.'
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.10'
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-02 00:00:00.000000000 Z
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.