todo-txt 0.6 → 0.7

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: 87c3206db6b8a924eeedaaee0699cbaa9a63ea0f
4
- data.tar.gz: ba6c31c870bd51c7a191a250bf20c9e1a8fbb5ea
3
+ metadata.gz: dd4d9a9131316d54020bfc771727481a05a7694f
4
+ data.tar.gz: 98e9a7d6a3ba5070db9521140d7d2f340a59cc27
5
5
  SHA512:
6
- metadata.gz: 0ee77ef0490c7b423a52f779b810af66521ed1ed253560cd08c5a1b207102fcf36e4ab6d3f78666039c49d748c27e9d96d2149e28eeb0d2b3ad60e7cc6307760
7
- data.tar.gz: 82050a6db87b76ef1c3ab51c428d26b7f045242628eeebbd3817b1c884634f73f159004435db20b9967bf40feb99a0d043afb4dab5502d9d7389417ba32909f9
6
+ metadata.gz: 5d7c8d30855037df15053d219e4051dbd2f93d29bca14fa2f7477b706d634a433a282f9e51d3a7239b92d63f5e47bf291463846c5f663ac19b31cff197e0772a
7
+ data.tar.gz: 1cd0e7eed6b6de21fc4e6d19b8addff687f0c513c1c823441696ff8dae4c9466ac9ca3283fa53290d6e2525f518c89ace94dafef66895b3b8fe24a1db978fd89
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
- rvm:
3
2
  rvm:
4
3
  - 2.0
5
4
  - 2.1
@@ -9,3 +8,5 @@ rvm:
9
8
  - jruby-9000
10
9
  - jruby-head
11
10
  - ruby-head
11
+ before_install: gem install bundler -v 1.10.6
12
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,15 +1,18 @@
1
1
  # Todo.txt
2
2
 
3
- [![Development Build Status](https://secure.travis-ci.org/samwho/todo-txt-gem.png?branch=develop)](http://travis-ci.org/samwho/todo-txt-gem)
4
- [![Master Build Status](https://secure.travis-ci.org/samwho/todo-txt-gem.png?branch=master)](http://travis-ci.org/samwho/todo-txt-gem)
3
+ [![Gem Version](http://img.shields.io/gem/v/todo-txt.svg)](https://rubygems.org/gems/todo-txt)
4
+ [![Build Status](https://travis-ci.org/samwho/todo-txt-gem.svg?branch=master)](https://travis-ci.org/samwho/todo-txt-gem)
5
5
 
6
6
  This is a Ruby client library for Gina Trapani's
7
7
  [todo.txt](https://github.com/ginatrapani/todo.txt-cli/). It allows for easy
8
- parsing of task lists and tasks in the todo.txt format.
8
+ management of task lists and tasks in the todo.txt format.
9
9
 
10
10
  Find the project on GitHub:
11
11
  [http://github.com/samwho/todo-txt-gem](http://github.com/samwho/todo-txt-gem).
12
12
 
13
+ Find the full API docs on Rubydoc.info:
14
+ [http://www.rubydoc.info/gems/todo-txt](http://www.rubydoc.info/gems/todo-txt).
15
+
13
16
  # Installation
14
17
 
15
18
  Installation is very simple. The project is packaged as a Ruby gem and can be
@@ -49,12 +52,12 @@ list.by_priority "A"
49
52
  list.by_context "@code"
50
53
  # => Returns a new Todo::List with only tasks that have a @code context.
51
54
 
52
- list.by_project "+manhatten"
55
+ list.by_project "+manhattan"
53
56
  # => Returns a new Todo::List with only tasks that are part of the
54
- # +manhatten project (see what I did there?)
57
+ # +manhattan project (see what I did there?)
55
58
 
56
59
  # And you can combine these, like so
57
- list.by_project("+manhatten").by_priority("B")
60
+ list.by_project("+manhattan").by_priority("B")
58
61
  ```
59
62
 
60
63
  ## Todo::Task
@@ -107,4 +110,4 @@ Tasks without a priority will always be less than a task with a priority.
107
110
 
108
111
  # Requirements
109
112
 
110
- The todo-txt gem requires Ruby 1.8.7 or higher.
113
+ The todo-txt gem requires Ruby 2.0 or higher.
@@ -1,21 +1,24 @@
1
1
  require 'logger'
2
2
 
3
3
  module Todo
4
+ # Handles depreciation warnings and other issues related to API usage
4
5
  module Logger
5
- def self.included base
6
+ def self.included(base)
6
7
  base.extend(self)
7
8
  end
8
9
 
9
- def self.logger= new_logger
10
- @@logger = new_logger
10
+ def logger
11
+ Todo::Logger.logger
11
12
  end
12
13
 
13
- def self.logger
14
- @@logger ||= ::Logger.new(STDOUT)
15
- end
14
+ class << self
15
+ # Sets a new logger object
16
+ attr_writer :logger
16
17
 
17
- def logger
18
- Todo::Logger.logger
18
+ # Creates a new logger object
19
+ def logger
20
+ @logger ||= ::Logger.new(STDOUT)
21
+ end
19
22
  end
20
23
  end
21
24
  end
@@ -1,33 +1,94 @@
1
1
  module Todo
2
2
  module Syntax
3
3
  # The regular expression used to match contexts.
4
- def contexts_regex
5
- /(?:\s+|^)@[^\s]+/
6
- end
4
+ CONTEXTS_PATTERN = /(?:\s+|^)@[^\s]+/.freeze
7
5
 
8
6
  # The regex used to match projects.
9
- def projects_regex
10
- /(?:\s+|^)\+[^\s]+/
11
- end
7
+ PROJECTS_PATTERN = /(?:\s+|^)\+[^\s]+/.freeze
12
8
 
13
9
  # The regex used to match priorities.
14
- def priority_regex
15
- /(?:^|\s+)\(([A-Za-z])\)\s+/
16
- end
10
+ PRIORITY_PATTERN = /(?:^|\s+)\(([A-Za-z])\)\s+/
17
11
 
18
12
  # The regex used to match creation date.
19
- def created_on_regex
20
- /(?:^|-\d{2}\s|\)\s)(\d{4}-\d{2}-\d{2})\s/
21
- end
13
+ CREATED_ON_PATTERN = /(?:^|-\d{2}\s|\)\s)(\d{4}-\d{2}-\d{2})\s/.freeze
22
14
 
23
15
  # The regex used to match completion.
24
- def done_regex
25
- /^x\s+(\d{4}-\d{2}-\d{2})\s+/
26
- end
16
+ COMPLETED_ON_PATTERN = /^x\s+(\d{4}-\d{2}-\d{2})\s+/.freeze
27
17
 
28
18
  # The regex used to match due date.
29
- def due_on_regex
30
- /(?:due:)(\d{4}-\d{2}-\d{2})(?:\s+|$)/i
19
+ DUE_ON_PATTERN = /(?:due:)(\d{4}-\d{2}-\d{2})(?:\s+|$)/i.freeze
20
+
21
+ def get_item_text(line)
22
+ line.
23
+ gsub(COMPLETED_ON_PATTERN, '').
24
+ gsub(PRIORITY_PATTERN, '').
25
+ gsub(CREATED_ON_PATTERN, '').
26
+ gsub(CONTEXTS_PATTERN, '').
27
+ gsub(PROJECTS_PATTERN, '').
28
+ gsub(DUE_ON_PATTERN, '').
29
+ strip
30
+ end
31
+
32
+ def orig_priority(line)
33
+ line.match(PRIORITY_PATTERN)[1] if line =~ PRIORITY_PATTERN
34
+ end
35
+
36
+ # Extracts the creation date for the given todo item.
37
+ # Returns nil if a valid date is not found.
38
+ #
39
+ # @param line [String] the todo item to be processed
40
+ # @return [Date] the created date of the line
41
+ def orig_created_on(line)
42
+ date = line.match CREATED_ON_PATTERN
43
+ begin
44
+ Date.parse(date[1]) if date
45
+ rescue ArgumentError
46
+ return nil # The given date is not valid
47
+ end
48
+ end
49
+
50
+ # Extracts the completion date for the given todo item.
51
+ # Returns nil if a valid date is not found.
52
+ #
53
+ # @param line [String] the todo item to be processed
54
+ # @return [Date] the completed date of the line
55
+ def get_completed_date(line)
56
+ date = COMPLETED_ON_PATTERN.match(line)
57
+ begin
58
+ Date.parse(date[1]) if date
59
+ rescue ArgumentError
60
+ return nil # The given date is not valid
61
+ end
62
+ end
63
+
64
+ # Extracts the completion date for the given todo item.
65
+ # Returns nil if a valid date is not found.
66
+ #
67
+ # @param line [String] the todo item to be processed
68
+ # @return [Date] the due date of the line
69
+ def get_due_on_date(line)
70
+ date = DUE_ON_PATTERN.match(line)
71
+ begin
72
+ Date.parse(date[1]) if date
73
+ rescue ArgumentError
74
+ return nil # The given date is not valid
75
+ end
76
+ end
77
+
78
+ # Extract the list of `@context` tags out of the task line.
79
+ #
80
+ # @param [String] line Line of text encoding a single task
81
+ # @return [Array<String>] List of context tags
82
+ def extract_contexts(line)
83
+ line.scan(CONTEXTS_PATTERN).map { |tag| tag.strip }
84
+ end
85
+
86
+ # Extract the list of `+project` tags out of the task line.
87
+ #
88
+ # @param [String] line Line of text encoding a single task
89
+ # @return [Array<String>] List of project tags
90
+ def extract_projects(line)
91
+ line.scan(PROJECTS_PATTERN).map { |tag| tag.strip }
31
92
  end
32
93
  end
33
94
  end
data/lib/todo-txt/task.rb CHANGED
@@ -14,11 +14,11 @@ module Todo
14
14
  # task = Todo::Task.new("(A) A high priority task!")
15
15
  def initialize task
16
16
  @orig = task
17
- @completed_on = get_completed_date #orig.scan(self.class.done_regex)[1] ||= nil
18
- @priority, @created_on = orig_priority, orig_created_on
19
- @due_on = get_due_on_date
20
- @contexts ||= orig.scan(contexts_regex).map { |item| item.strip }
21
- @projects ||= orig.scan(projects_regex).map { |item| item.strip }
17
+ @completed_on = get_completed_date(orig)
18
+ @priority, @created_on = orig_priority(orig), orig_created_on(orig)
19
+ @due_on = get_due_on_date(orig)
20
+ @contexts ||= extract_contexts(orig)
21
+ @projects ||= extract_projects(orig)
22
22
  end
23
23
 
24
24
  # Returns the original content of the task.
@@ -103,14 +103,7 @@ module Todo
103
103
  # task = Todo::Task.new "(A) @test Testing!"
104
104
  # task.text #=> "Testing!"
105
105
  def text
106
- @text ||= orig.
107
- gsub(done_regex, '').
108
- gsub(priority_regex, '').
109
- gsub(created_on_regex, '').
110
- gsub(contexts_regex, '').
111
- gsub(projects_regex, '').
112
- gsub(due_on_regex, '').
113
- strip
106
+ @text ||= get_item_text(orig)
114
107
  end
115
108
 
116
109
  # Returns the task's creation date, if any.
@@ -195,7 +188,27 @@ module Todo
195
188
  # #=> nil
196
189
  def undo!
197
190
  @completed_on = nil
198
- @priority = orig_priority
191
+ @priority = orig_priority(orig)
192
+ end
193
+
194
+ # Increases the priority until A. If it's nil, it sets it to A.
195
+ # @return [Char] the new priority of the task
196
+ def priority_inc!
197
+ if @priority.nil?
198
+ @priority = 'A'
199
+ elsif @priority.ord > 65
200
+ @priority = (@priority.ord - 1).chr
201
+ end
202
+ @priority
203
+ end
204
+
205
+ # Decreases the priority until Z. if it's nil, it does nothing and
206
+ # returns nil.
207
+ # @return [Char] the new priority of the task
208
+ def priority_dec!
209
+ return if @priority.nil?
210
+ @priority = @priority.next if @priority.ord < 90
211
+ @priority
199
212
  end
200
213
 
201
214
  # Toggles the task from complete to incomplete or vice versa.
@@ -260,36 +273,5 @@ module Todo
260
273
  other_task.priority <=> self.priority
261
274
  end
262
275
  end
263
-
264
- private
265
-
266
- def orig_priority
267
- @orig.match(priority_regex)[1] if @orig =~ priority_regex
268
- end
269
-
270
- def orig_created_on
271
- begin
272
- if @orig =~ created_on_regex
273
- date = @orig.match created_on_regex
274
- return Date.parse(date[1]) unless date.nil?
275
- end
276
- rescue; end
277
- nil
278
- end
279
-
280
- def get_completed_date
281
- begin
282
- return Date.parse(done_regex.match(@orig)[1])
283
- rescue; end
284
- nil
285
- end
286
-
287
- def get_due_on_date
288
- begin
289
- return Date.parse(due_on_regex.match(@orig)[1])
290
- rescue; end
291
- nil
292
- end
293
-
294
276
  end
295
277
  end
@@ -4,75 +4,116 @@ describe Todo::List do
4
4
  let(:path) { File.dirname(__FILE__) + '/../data/todo.txt' }
5
5
  let(:list) { Todo::List.new(path) }
6
6
 
7
- it 'should have the correct path' do
7
+ context 'create with an array' do
8
+ it 'successfully creates an object' do
9
+ array = Array.new
10
+ array.push "(A) A string task!"
11
+ array.push Todo::Task.new("(A) An actual task!")
12
+ expect(Todo::List.new array).not_to eq(nil)
13
+ end
14
+
15
+ it 'does not have a path' do
16
+ array = Array.new
17
+ array.push "(A) A string task!"
18
+ array.push Todo::Task.new("(A) An actual task!")
19
+ expect(Todo::List.new(array).path).to eq(nil)
20
+ end
21
+ end
22
+
23
+ it 'accepts a mix of tasks and strings' do
24
+ l = Todo::List.new([
25
+ "A task!",
26
+ Todo::Task.new("Another task!"),
27
+ ])
28
+
29
+ expect(l.length).to eq(2)
30
+ end
31
+
32
+ it 'has the correct path' do
8
33
  expect(list.path).to eq(path)
9
34
  end
10
35
 
11
- it 'should grab a list of Todo::Tasks' do
36
+ it 'creates a list of Todo::Tasks' do
12
37
  list.each do |task|
13
38
  expect(task.class).to eq(Todo::Task)
14
39
  end
40
+ end
15
41
 
16
- # This is a little bit fragile but it helps me sleep at night.
17
- expect(list[0].priority).to eq("A")
42
+ it 'it retrieves the list in the expected order' do
43
+ expect(list.first.text).to eq('Crack the Da Vinci Code.')
44
+ expect(list.last.text).to eq(
45
+ 'This task is completed and has created and completion dates')
18
46
  end
19
47
 
20
- it 'should be able to filter by priority' do
21
- list.by_priority("A").each do |task|
22
- expect(task.priority).to eq("A")
23
- end
48
+ it 'it retrieves the expected number of items' do
49
+ expect(list.count).to eq(11)
50
+ end
24
51
 
52
+ it 'should be able to filter by priority' do
25
53
  # Make sure some data was actually checked
26
- expect(list.by_priority("A").length).to be > 0
27
- end
54
+ priority_list = list.by_priority('A')
55
+ expect(priority_list.length).to be > 0
28
56
 
29
- it 'should be able to filter by context' do
30
- list.by_context("@context").each do |task|
31
- expect(task.contexts).to include "@context"
57
+ priority_list.each do |task|
58
+ expect(task.priority).to eq('A')
32
59
  end
60
+ end
33
61
 
62
+ it 'should be able to filter by context' do
34
63
  # Make sure some data was actually checked
35
- expect(list.by_context("@context").length).to be > 0
36
- end
64
+ context_list = list.by_context('@context')
65
+ expect(context_list.length).to be > 0
37
66
 
38
- it 'should be able to filter by project' do
39
- list.by_project("+project").each do |task|
40
- expect(task.projects).to include "+project"
67
+ context_list.each do |task|
68
+ expect(task.contexts).to include '@context'
41
69
  end
70
+ end
42
71
 
72
+ it 'should be able to filter by project' do
43
73
  # Make sure some data was actually checked
44
- expect(list.by_project("+project").length).to be > 0
74
+ project_list = list.by_project('+project')
75
+ expect(project_list.length).to be > 0
76
+
77
+ project_list.each do |task|
78
+ expect(task.projects).to include '+project'
79
+ end
45
80
  end
46
81
 
47
82
  it 'should be able to filter by project, context and priority' do
48
- filtered = list.by_project("+project").
49
- by_context("@context").
50
- by_priority("C")
83
+ filtered = list.by_project('+project').
84
+ by_context('@context').
85
+ by_priority('C')
86
+
87
+ # Make sure some data was actually checked
88
+ expect(filtered.length).to be > 0
51
89
 
52
90
  filtered.each do |task|
53
- expect(task.projects).to include "+project"
54
- expect(task.contexts).to include "@context"
55
- expect(task.priority).to eq("C")
91
+ expect(task.projects).to include '+project'
92
+ expect(task.contexts).to include '@context'
93
+ expect(task.priority).to eq('C')
56
94
  end
95
+ end
96
+
97
+ it 'filters by done' do
98
+ done_list = list.by_done
57
99
 
58
100
  # Make sure some data was actually checked
59
- expect(filtered.length).to be > 0
60
- end
101
+ expect(done_list.length).to eq(2)
61
102
 
62
- it 'should be able to filter by done' do
63
103
  list.by_done.each do |task|
64
104
  expect(task.text).to include 'This task is completed'
65
105
  end
66
-
67
- expect(list.by_done.length).to eq(2)
68
106
  end
69
107
 
70
- it 'should be able to filter by not done' do
71
- list.by_not_done.each do |task|
108
+ it 'filters by not done' do
109
+ not_done_list = list.by_not_done
110
+
111
+ # Make sure some data was actually checked
112
+ expect(not_done_list.length).to eq(9)
113
+
114
+ not_done_list.each do |task|
72
115
  expect(task.text).not_to include 'This task is completed'
73
116
  end
74
-
75
- expect(list.by_not_done.length).to eq(9)
76
117
  end
77
118
 
78
119
  it 'should be sortable' do
@@ -82,20 +123,10 @@ describe Todo::List do
82
123
 
83
124
  # Make sure some data was actually checked
84
125
  expect(list.sort.length).to be > 0
85
-
86
- # Class should still be Todo::List
87
- # This assertion currently fails. TODO.
88
- # list.sort.should be_a Todo::List
89
126
  end
90
127
 
91
- describe 'manual list creation' do
92
- it 'should be possible with a mix of tasks and strings' do
93
- l = Todo::List.new([
94
- "A task!",
95
- Todo::Task.new("Another task!"),
96
- ])
97
-
98
- expect(l.length).to eq(2)
99
- end
100
- end
128
+ it 'returns a list on sort'
129
+ # Class should still be Todo::List
130
+ # This assertion currently fails. TODO.
131
+ # expect(list.sort).to be_a Todo::List
101
132
  end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Todo::Syntax do
4
+ include Todo::Syntax
5
+
6
+ describe '#get_context_tags' do
7
+ specify 'empty task' do
8
+ expect(extract_contexts('')).to eq([])
9
+ end
10
+
11
+ specify 'task without context' do
12
+ expect(extract_contexts('something to do')).to eq([])
13
+ end
14
+
15
+ specify 'task with single context' do
16
+ expect(extract_contexts('something to do @work')).to eq(['@work'])
17
+ end
18
+
19
+ specify 'task with multiple contexts' do
20
+ expect(extract_contexts('something to do @work @play')).to eq(['@work', '@play'])
21
+ end
22
+ end
23
+
24
+ describe '#get_project_tags' do
25
+ specify 'empty task' do
26
+ expect(extract_projects('')).to eq([])
27
+ end
28
+
29
+ specify 'task without project' do
30
+ expect(extract_projects('something to do')).to eq([])
31
+ end
32
+
33
+ specify 'task with single project' do
34
+ expect(extract_projects('something to do +report')).to eq(['+report'])
35
+ end
36
+
37
+ specify 'task with multiple projects' do
38
+ expect(extract_projects('something to do +report +analysis')).to eq(['+report', '+analysis'])
39
+ end
40
+ end
41
+
42
+ describe '#orig_priority' do
43
+ specify 'empty task' do
44
+ expect(orig_priority('')).to be nil
45
+ end
46
+
47
+ specify 'task without priority' do
48
+ expect(orig_priority('something to do')).to be nil
49
+ end
50
+
51
+ specify 'task with priority A' do
52
+ expect(orig_priority('(A) something to do')).to eq('A')
53
+ end
54
+
55
+ specify 'task with priority B' do
56
+ expect(orig_priority('(B) something to do')).to eq('B')
57
+ end
58
+ end
59
+
60
+ describe '#orig_created_on' do
61
+ specify 'empty task' do
62
+ expect(orig_created_on('')).to be nil
63
+ end
64
+
65
+ specify 'task without date' do
66
+ expect(orig_created_on('something to do')).to be nil
67
+ end
68
+
69
+ specify 'task with created date' do
70
+ expect(orig_created_on('2016-03-29 something to do')).to eq(Date.new(2016, 03, 29))
71
+ end
72
+
73
+ specify 'prioritised task with created date' do
74
+ expect(orig_created_on('(A) 2016-03-29 something to do')).to eq(Date.new(2016, 03, 29))
75
+ end
76
+
77
+ specify 'date included in task text' do
78
+ expect(orig_created_on('(A) something to do on 2016-03-29')).to be nil
79
+ end
80
+ end
81
+
82
+ describe '#get_completed_date' do
83
+ specify 'empty task' do
84
+ expect(get_completed_date('')).to be nil
85
+ end
86
+
87
+ specify 'uncompleted task' do
88
+ expect(get_completed_date('2016-03-29 something to do')).to be nil
89
+ end
90
+
91
+ specify 'completed task without date' do
92
+ expect(get_completed_date('2016-03-29 something to do')).to be nil
93
+ end
94
+
95
+ specify 'completed task without date' do
96
+ expect(get_completed_date('2016-03-29 something to do')).to be nil
97
+ end
98
+ end
99
+
100
+ describe '#get_due_on_date' do
101
+ specify 'empty task' do
102
+ expect(get_due_on_date('')).to be nil
103
+ end
104
+
105
+ specify 'task without due date' do
106
+ expect(get_due_on_date('something to do')).to be nil
107
+ end
108
+
109
+ specify 'task with due date' do
110
+ expect(get_due_on_date('something to do due:2016-03-30')).to eq(Date.new(2016, 03, 30))
111
+ end
112
+ end
113
+
114
+ describe '#get_item_text' do
115
+ specify 'empty task' do
116
+ expect(get_item_text('')).to eq('')
117
+ end
118
+
119
+ specify 'task without markup' do
120
+ expect(get_item_text('something to do')).to eq('something to do')
121
+ end
122
+
123
+ specify 'task with date, priority, projects and context' do
124
+ expect(get_item_text('(A) 2016-03-29 something to do +experiment @work')).to eq('something to do')
125
+ end
126
+
127
+ specify 'completed task with projects and context' do
128
+ expect(get_item_text('x 2016-03-30 2016-03-29 something to do +experiment @work')).to eq('something to do')
129
+ end
130
+ end
131
+ end
@@ -1,131 +1,203 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Todo::Task do
4
- describe "Descriptions:" do
4
+ describe 'Descriptions:' do
5
5
  it 'should convert to a string' do
6
- task = Todo::Task.new "(A) 2012-12-08 My task @test +test2"
7
- expect(task.to_s).to eq("(A) 2012-12-08 My task @test +test2")
6
+ task = Todo::Task.new '(A) 2012-12-08 My task @test +test2'
7
+ expect(task.to_s).to eq('(A) 2012-12-08 My task @test +test2')
8
8
  end
9
9
 
10
10
  it 'should keep track of the original string after changing the task' do
11
- task = Todo::Task.new "(A) 2012-12-08 My task @test +test2"
11
+ task = Todo::Task.new '(A) 2012-12-08 My task @test +test2'
12
12
  Timecop.freeze(2013, 12, 8) do
13
13
  task.do!
14
- expect(task.orig).to eq("(A) 2012-12-08 My task @test +test2")
14
+ expect(task.orig).to eq('(A) 2012-12-08 My task @test +test2')
15
15
  end
16
16
  end
17
17
 
18
18
  it 'should be modifiable' do
19
- task = Todo::Task.new "2012-12-08 My task @test +test2"
19
+ task = Todo::Task.new '2012-12-08 My task @test +test2'
20
20
  task.projects.clear
21
- task.contexts << ["@test3"]
21
+ task.contexts << ['@test3']
22
22
  Timecop.freeze(2013, 12, 8) do
23
23
  task.do!
24
- expect(task.to_s).to eq("x 2013-12-08 2012-12-08 My task @test @test3")
24
+ expect(task.to_s).to eq('x 2013-12-08 2012-12-08 My task @test @test3')
25
25
  end
26
26
  end
27
27
 
28
28
  it 'should be able to get just the text, no due date etc.' do
29
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project"
30
- expect(task.text).to eq("This is a sweet task.")
29
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project'
30
+ expect(task.text).to eq('This is a sweet task.')
31
31
  end
32
32
 
33
33
  it 'should retain the original task creation string' do
34
- task = Todo::Task.new "(A) This is an awesome task, yo. +winning"
35
- expect(task.orig).to eq("(A) This is an awesome task, yo. +winning")
34
+ task = Todo::Task.new '(A) This is an awesome task, yo. +winning'
35
+ expect(task.orig).to eq('(A) This is an awesome task, yo. +winning')
36
36
  end
37
37
 
38
38
  it 'should be able to get just the text, no contexts etc.' do
39
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project"
40
- expect(task.text).to eq("This is a sweet task.")
39
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project'
40
+ expect(task.text).to eq('This is a sweet task.')
41
41
  end
42
42
  end
43
43
 
44
- describe "Priorities:" do
44
+ describe 'Priorities:' do
45
45
  it 'should recognise priorities' do
46
- task = Todo::Task.new "(A) Hello world!"
47
- expect(task.priority).to eq("A")
46
+ task = Todo::Task.new '(A) Hello world!'
47
+ expect(task.priority).to eq('A')
48
48
  end
49
49
 
50
50
  it 'should only recognise priorities at the start of a task' do
51
- task = Todo::Task.new "Hello, world! (A)"
51
+ task = Todo::Task.new 'Hello, world! (A)'
52
52
  expect(task.priority).to eq(nil)
53
53
  end
54
54
 
55
55
  it 'should recognize priorities around dates' do
56
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project"
57
- expect(task.priority).to eq("B")
56
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project'
57
+ expect(task.priority).to eq('B')
58
58
  end
59
59
 
60
60
  it 'should remove the priority when calling Task#do!' do
61
- task = Todo::Task.new "(A) Task"
61
+ task = Todo::Task.new '(A) Task'
62
62
  task.do!
63
63
  expect(task.priority).to be_nil
64
64
  end
65
65
 
66
66
  it 'should reset to the original priority when calling Task#undo!' do
67
- task = Todo::Task.new "(A) Task"
67
+ task = Todo::Task.new '(A) Task'
68
68
  task.do!
69
69
  task.undo!
70
- expect(task.priority).to eq("A")
70
+ expect(task.priority).to eq('A')
71
71
  end
72
72
  end
73
73
 
74
- describe "Completion:" do
74
+ describe 'Step priority:' do
75
+ context 'Increment' do
76
+ it 'increments the priority by one' do
77
+ task = Todo::Task.new '(B) Task'
78
+ task.priority_inc!
79
+ expect(task.priority).to eq('A')
80
+ end
81
+
82
+ it 'returns the new priority' do
83
+ task = Todo::Task.new '(B) Task'
84
+ expect(task.priority_inc!).to eq('A')
85
+ end
86
+
87
+ it 'does not increment priority beyond A' do
88
+ task = Todo::Task.new '(A) Task'
89
+ task.priority_inc!
90
+ expect(task.priority).to eq('A')
91
+ end
92
+
93
+ it 'returns A if the priority did not change' do
94
+ task = Todo::Task.new '(A) Task'
95
+ expect(task.priority_inc!).to eq('A')
96
+ end
97
+
98
+ it 'sets a priority if previous priority was nil' do
99
+ task = Todo::Task.new 'Task'
100
+ task.priority_inc!
101
+ expect(task.priority).to eq('A')
102
+ end
103
+
104
+ it 'returns A if the previous priority was nil' do
105
+ task = Todo::Task.new 'Task'
106
+ expect(task.priority_inc!).to eq('A')
107
+ end
108
+ end
109
+
110
+ context 'Decrement' do
111
+ it 'lowers the priority by one' do
112
+ task = Todo::Task.new '(A) Task'
113
+ task.priority_dec!
114
+ expect(task.priority).to eq('B')
115
+ end
116
+
117
+ it 'returns the new priority' do
118
+ task = Todo::Task.new '(A) Task'
119
+ expect(task.priority_dec!).to eq('B')
120
+ end
121
+
122
+ it 'does not go below Z' do
123
+ task = Todo::Task.new '(Z) Task'
124
+ task.priority_dec!
125
+ expect(task.priority).to eq('Z')
126
+ end
127
+
128
+ it 'returns Z if priority did not change' do
129
+ task = Todo::Task.new '(Z) Task'
130
+ expect(task.priority_dec!).to eq('Z')
131
+ end
132
+
133
+ it 'does not set a priority if priority was nil' do
134
+ task = Todo::Task.new 'Task'
135
+ task.priority_dec!
136
+ expect(task.priority).to eq(nil)
137
+ end
138
+
139
+ it 'returns nil if priority was nil' do
140
+ task = Todo::Task.new 'Task'
141
+ expect(task.priority_dec!).to eq(nil)
142
+ end
143
+ end
144
+ end
145
+
146
+ describe 'Completion:' do
75
147
  it 'should be not done with missing date' do
76
- task = Todo::Task.new "x This is not done"
148
+ task = Todo::Task.new 'x This is not done'
77
149
  expect(task.done?).to be false
78
150
  end
79
151
 
80
152
  it 'should be not done with malformed date' do
81
- task = Todo::Task.new "x 01-01-2013 This is not done"
153
+ task = Todo::Task.new 'x 01-01-2013 This is not done'
82
154
  expect(task.done?).to be false
83
155
  expect(task.completed_on).to be nil
84
156
  end
85
157
 
86
158
  it 'should be not done with an invalid date' do
87
- task = Todo::Task.new "x 2013-02-31 This is not done"
159
+ task = Todo::Task.new 'x 2013-02-31 This is not done'
88
160
  expect(task.done?).to be false
89
161
  expect(task.completed_on).to be nil
90
162
  end
91
163
 
92
164
  it 'should be done on 2013-04-22' do
93
- task = Todo::Task.new "x 2013-04-22 This is really done"
165
+ task = Todo::Task.new 'x 2013-04-22 This is really done'
94
166
  expect(task.done?).to be true
95
167
  expect(task.completed_on).to eq(Date.parse('22th April 2013'))
96
168
  end
97
169
 
98
170
  it 'should be able to recognise completed tasks' do
99
- task = Todo::Task.new "x 2012-12-08 This is done!"
171
+ task = Todo::Task.new 'x 2012-12-08 This is done!'
100
172
  expect(task.done?).to be true
101
173
  end
102
174
 
103
175
  it 'should not recognize incomplete tasks as done' do
104
- task = Todo::Task.new "2012-12-08 This ain't done!"
176
+ task = Todo::Task.new '2012-12-08 This is not done!'
105
177
  expect(task.done?).to be false
106
178
  end
107
179
 
108
180
  it 'should be completable' do
109
- task = Todo::Task.new "2012-12-08 This ain't done!"
181
+ task = Todo::Task.new '2012-12-08 This is not done!'
110
182
  task.do!
111
183
  expect(task.done?).to be true
112
184
  end
113
185
 
114
186
  it 'should be marked as incomplete' do
115
- task = Todo::Task.new "x 2012-12-08 This is done!"
187
+ task = Todo::Task.new 'x 2012-12-08 This is done!'
116
188
  task.undo!
117
189
  expect(task.done?).to be false
118
190
  end
119
191
 
120
192
  it 'should be marked as incomplete without any date' do
121
- task = Todo::Task.new "x 2012-12-08 This is done!"
193
+ task = Todo::Task.new 'x 2012-12-08 This is done!'
122
194
  task.undo!
123
195
  expect(task.completed_on).to be_nil
124
196
  expect(task.created_on).to be_nil
125
197
  end
126
198
 
127
199
  it 'should be toggable' do
128
- task = Todo::Task.new "2012-12-08 This ain't done!"
200
+ task = Todo::Task.new '2012-12-08 This is not done!'
129
201
  task.toggle!
130
202
  expect(task.done?).to be true
131
203
  task.toggle!
@@ -133,93 +205,93 @@ describe Todo::Task do
133
205
  end
134
206
  end
135
207
 
136
- describe "Contexts:" do
208
+ describe 'Contexts:' do
137
209
  it 'should recognise contexts' do
138
- task = Todo::Task.new "Hello, world! @test"
139
- expect(task.contexts).to eq(["@test"])
210
+ task = Todo::Task.new 'Hello, world! @test'
211
+ expect(task.contexts).to eq(['@test'])
140
212
  end
141
213
 
142
214
  it 'should recognise multiple contexts' do
143
- task = Todo::Task.new "Hello, world! @test @test2"
144
- expect(task.contexts).to eq(["@test", "@test2"])
215
+ task = Todo::Task.new 'Hello, world! @test @test2'
216
+ expect(task.contexts).to eq(['@test', '@test2'])
145
217
  end
146
218
 
147
219
  it 'should recognise contexts with dashes and underscores' do
148
- task = Todo::Task.new "Hello, world! @test-me @test2_me"
149
- expect(task.contexts).to eq(["@test-me", "@test2_me"])
220
+ task = Todo::Task.new 'Hello, world! @test-me @test2_me'
221
+ expect(task.contexts).to eq(['@test-me', '@test2_me'])
150
222
  end
151
223
  end
152
224
 
153
- describe "Projects:" do
225
+ describe 'Projects:' do
154
226
  it 'should recognise projects' do
155
- task = Todo::Task.new "Hello, world! +test"
156
- expect(task.projects).to eq(["+test"])
227
+ task = Todo::Task.new 'Hello, world! +test'
228
+ expect(task.projects).to eq(['+test'])
157
229
  end
158
230
 
159
231
  it 'should recognise multiple projects' do
160
- task = Todo::Task.new "Hello, world! +test +test2"
161
- expect(task.projects).to eq(["+test", "+test2"])
232
+ task = Todo::Task.new 'Hello, world! +test +test2'
233
+ expect(task.projects).to eq(['+test', '+test2'])
162
234
  end
163
235
 
164
236
  it 'should recognise projects with dashes and underscores' do
165
- task = Todo::Task.new "Hello, world! +test-me +test2_me"
166
- expect(task.projects).to eq(["+test-me", "+test2_me"])
237
+ task = Todo::Task.new 'Hello, world! +test-me +test2_me'
238
+ expect(task.projects).to eq(['+test-me', '+test2_me'])
167
239
  end
168
240
  end
169
241
 
170
- describe "Creation dates:" do
242
+ describe 'Creation dates:' do
171
243
  it 'should be able to recognise creation dates' do
172
- task = Todo::Task.new "(C) 2012-03-04 This has a date!"
173
- expect(task.created_on).to eq(Date.parse("4th March 2012"))
244
+ task = Todo::Task.new '(C) 2012-03-04 This has a date!'
245
+ expect(task.created_on).to eq(Date.parse('4th March 2012'))
174
246
  end
175
247
 
176
248
  it 'should be able to recognise creation dates without priority' do
177
- task = Todo::Task.new "2012-03-04 This has a date!"
178
- expect(task.created_on).to eq(Date.parse("4th March 2012"))
249
+ task = Todo::Task.new '2012-03-04 This has a date!'
250
+ expect(task.created_on).to eq(Date.parse('4th March 2012'))
179
251
  end
180
252
 
181
253
  it 'should return nil if no creation date is present' do
182
- task = Todo::Task.new "No date!"
254
+ task = Todo::Task.new 'No date!'
183
255
  expect(task.created_on).to be_nil
184
256
  end
185
257
 
186
258
  it 'should not recognise malformed dates' do
187
- task = Todo::Task.new "03-04-2012 This has a malformed date!"
259
+ task = Todo::Task.new '03-04-2012 This has a malformed date!'
188
260
  expect(task.created_on).to be_nil
189
261
  end
190
262
 
191
263
  it 'should be able to tell if the task is overdue' do
192
- task = Todo::Task.new((Date.today - 1).to_s + " This task is overdue!")
264
+ task = Todo::Task.new((Date.today - 1).to_s + ' This task is overdue!')
193
265
  expect(task.overdue?).to be false
194
266
  end
195
267
 
196
268
  it 'should return false on overdue? if there is no creation date' do
197
- task = Todo::Task.new "No date!"
269
+ task = Todo::Task.new 'No date!'
198
270
  expect(task.overdue?).to be false
199
271
  end
200
272
 
201
273
  it 'should return nil on ridiculous date data' do
202
- task = Todo::Task.new "2012-56-99 This has a malformed date!"
274
+ task = Todo::Task.new '2012-56-99 This has a malformed date!'
203
275
  expect(task.created_on).to be_nil
204
276
  end
205
277
  end
206
278
 
207
- describe "Completion dates:" do
279
+ describe 'Completion dates:' do
208
280
  it 'should be able to recognise completion dates' do
209
- task = Todo::Task.new "x 2012-12-08 This is done!"
210
- expect(task.completed_on).to eq(Date.parse("8th December 2012"))
281
+ task = Todo::Task.new 'x 2012-12-08 This is done!'
282
+ expect(task.completed_on).to eq(Date.parse('8th December 2012'))
211
283
  end
212
284
 
213
285
  it 'should set the current completion dates when calling Task#do!' do
214
- task = Todo::Task.new "2012-12-08 Task"
286
+ task = Todo::Task.new '2012-12-08 Task'
215
287
  Timecop.freeze(2013, 12, 8) do
216
288
  task.do!
217
- expect(task.completed_on).to eq(Date.parse("8th December 2013"))
289
+ expect(task.completed_on).to eq(Date.parse('8th December 2013'))
218
290
  end
219
291
  end
220
292
  end
221
293
 
222
- describe "Due dates:" do
294
+ describe 'Due dates:' do
223
295
  it 'should have a due date' do
224
296
  task = Todo::Task.new '(A) this task has due date due:2013-12-22'
225
297
  expect(task.due_on).not_to be_nil
@@ -245,17 +317,17 @@ describe Todo::Task do
245
317
  end
246
318
 
247
319
  it 'should convert to a string with due date' do
248
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project"
249
- expect(task.to_s).to eq("x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project due:2012-01-01")
320
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project'
321
+ expect(task.to_s).to eq('x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project due:2012-01-01')
250
322
  end
251
323
 
252
324
  it 'should have no due date with malformed date' do
253
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:01-01-2012 +project"
325
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:01-01-2012 +project'
254
326
  expect(task.due_on).to be_nil
255
327
  end
256
328
 
257
329
  it 'should have no due date with invalid date' do
258
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
330
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project'
259
331
  expect(task.due_on).to be_nil
260
332
  end
261
333
 
@@ -265,56 +337,56 @@ describe Todo::Task do
265
337
  end
266
338
 
267
339
  it 'should reset to the original due date when calling Task#undo!' do
268
- task = Todo::Task.new "2012-12-08 Task"
340
+ task = Todo::Task.new '2012-12-08 Task'
269
341
  Timecop.freeze(2013, 12, 8) do
270
342
  task.do!
271
343
  task.undo!
272
- expect(task.created_on).to eq(Date.parse("8th December 2012"))
344
+ expect(task.created_on).to eq(Date.parse('8th December 2012'))
273
345
  end
274
346
  end
275
347
 
276
348
  it 'should manage dates when calling Task#toggle!' do
277
- task = Todo::Task.new "2012-12-08 This ain't done!"
349
+ task = Todo::Task.new '2012-12-08 This is not done!'
278
350
  Timecop.freeze(2013, 12, 8) do
279
351
  task.toggle!
280
- expect(task.completed_on).to eq(Date.parse("8th December 2013"))
281
- expect(task.created_on).to eq(Date.parse("8th December 2012"))
352
+ expect(task.completed_on).to eq(Date.parse('8th December 2013'))
353
+ expect(task.created_on).to eq(Date.parse('8th December 2012'))
282
354
  task.toggle!
283
- expect(task.created_on).to eq(Date.parse("8th December 2012"))
355
+ expect(task.created_on).to eq(Date.parse('8th December 2012'))
284
356
  expect(task.completed_on).to be_nil
285
357
  end
286
358
  end
287
359
  end
288
360
 
289
- describe "Comparisons:" do
361
+ describe 'Comparisons:' do
290
362
  it 'should be comparable' do
291
- task1 = Todo::Task.new "(A) Top priority, y'all!"
292
- task2 = Todo::Task.new "(B) Not quite so high."
363
+ task1 = Todo::Task.new '(A) Top priority!'
364
+ task2 = Todo::Task.new '(B) Not quite so high.'
293
365
 
294
366
  assertion = task1 > task2
295
367
  expect(assertion).to eq(true)
296
368
  end
297
369
 
298
370
  it 'should be comparable to task without priority' do
299
- task1 = Todo::Task.new "Top priority, y'all!"
300
- task2 = Todo::Task.new "(B) Not quite so high."
371
+ task1 = Todo::Task.new 'Top priority!'
372
+ task2 = Todo::Task.new '(B) Not quite so high.'
301
373
 
302
374
  assertion = task1 < task2
303
375
  expect(assertion).to eq(true)
304
376
  end
305
377
 
306
378
  it 'should be able to compare two tasks without priority' do
307
- task1 = Todo::Task.new "Top priority, y'all!"
308
- task2 = Todo::Task.new "Not quite so high."
379
+ task1 = Todo::Task.new 'Top priority!'
380
+ task2 = Todo::Task.new 'Not quite so high.'
309
381
 
310
382
  assertion = task1 == task2
311
383
  expect(assertion).to eq(true)
312
384
  end
313
385
  end
314
386
 
315
- describe "Logging:" do
387
+ describe 'Logging:' do
316
388
  it 'should have a logger' do
317
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
389
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project'
318
390
  expect(task.logger).not_to be nil
319
391
  end
320
392
 
@@ -322,7 +394,7 @@ describe Todo::Task do
322
394
  logger = double(Logger)
323
395
  Todo::Logger.logger = logger
324
396
 
325
- task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
397
+ task = Todo::Task.new 'x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project'
326
398
  error_message = 'Task#date is deprecated, use created_on instead.'
327
399
 
328
400
  expect(logger).to receive(:warn).with(error_message)
data/todo-txt.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{todo-txt}
3
- s.version = "0.6"
3
+ s.version = '0.7'
4
4
  s.authors = ["Sam Rose"]
5
5
  s.email = %q{samwho@lbak.co.uk}
6
6
  s.summary = %q{A client library for parsing todo.txt files.}
7
7
  s.homepage = %q{http://github.com/samwho/todo-txt-gem}
8
8
  s.description = %q{Allows for simple parsing of todo.txt files, as per Gina Trapani's todo.txt project.}
9
- s.required_ruby_version = '>= 1.8.7'
9
+ s.required_ruby_version = '>= 2.0'
10
10
  s.license = 'GPL-2'
11
11
 
12
12
  # Add all files to the files parameter.
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.6'
4
+ version: '0.7'
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-03-10 00:00:00.000000000 Z
11
+ date: 2016-04-04 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.
@@ -32,6 +32,7 @@ files:
32
32
  - spec/data/todo.txt
33
33
  - spec/spec_helper.rb
34
34
  - spec/todo-txt/list_spec.rb
35
+ - spec/todo-txt/syntax_spec.rb
35
36
  - spec/todo-txt/task_spec.rb
36
37
  - todo-txt.gemspec
37
38
  homepage: http://github.com/samwho/todo-txt-gem
@@ -46,7 +47,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
47
  requirements:
47
48
  - - ">="
48
49
  - !ruby/object:Gem::Version
49
- version: 1.8.7
50
+ version: '2.0'
50
51
  required_rubygems_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - ">="