todo-txt 0.3.1 → 0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aab28ef27bccaf771aff05bbc5dbff0ac330143f
4
+ data.tar.gz: 454ff5faf63eaf1fbec2ed0e25fbb87ae6784c41
5
+ SHA512:
6
+ metadata.gz: 25cddbf92e85d098afa16bda2a3cf33a9ed5d8dc7fe60362194c8993b8073f6595838b982ca6e173b884da5cdd009211925270b3bc0e4063874fc0b2b80713f4
7
+ data.tar.gz: 2855f72b5b3417517d1126ab35c68c80a96663e8676309f31b5ab853d8a70d1e4406c051159abe317abd051f1fc585097c4ad189f155fceccf167b0921ad74e7
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'rspec'
5
5
  gem 'rake'
6
+ gem 'timecop'
7
+ end
8
+
9
+ group :development do
10
+ gem 'bundler'
6
11
  end
@@ -1,5 +1,5 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  diff-lcs (1.1.3)
5
5
  rake (0.9.2.2)
@@ -11,10 +11,13 @@ GEM
11
11
  rspec-expectations (2.9.1)
12
12
  diff-lcs (~> 1.1.3)
13
13
  rspec-mocks (2.9.0)
14
+ timecop (0.6.1)
14
15
 
15
16
  PLATFORMS
16
17
  ruby
17
18
 
18
19
  DEPENDENCIES
20
+ bundler
19
21
  rake
20
22
  rspec
23
+ timecop
data/README.md CHANGED
@@ -3,13 +3,17 @@
3
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
4
  [![Master Build Status](https://secure.travis-ci.org/samwho/todo-txt-gem.png?branch=master)](http://travis-ci.org/samwho/todo-txt-gem)
5
5
 
6
- This is a Ruby client library for Gina Trapani's [todo.txt](https://github.com/ginatrapani/todo.txt-cli/). It allows for easy parsing of task lists and tasks in the todo.txt format.
6
+ This is a Ruby client library for Gina Trapani's
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.
7
9
 
8
- Find the project on GitHub: [http://github.com/samwho/todo-txt-gem](http://github.com/samwho/todo-txt-gem).
10
+ Find the project on GitHub:
11
+ [http://github.com/samwho/todo-txt-gem](http://github.com/samwho/todo-txt-gem).
9
12
 
10
13
  # Installation
11
14
 
12
- Installation is very simple. The project is packaged as a Ruby gem and can be installed by running:
15
+ Installation is very simple. The project is packaged as a Ruby gem and can be
16
+ installed by running:
13
17
 
14
18
  gem install todo-txt
15
19
 
@@ -17,76 +21,91 @@ Installation is very simple. The project is packaged as a Ruby gem and can be in
17
21
 
18
22
  ## Todo::List
19
23
 
20
- A `Todo::List` object encapsulates your todo.txt file. You initialise it by passing the path to your todo.txt to the constructor:
24
+ A `Todo::List` object encapsulates your todo.txt file. You initialise it by
25
+ passing the path to your todo.txt to the constructor:
21
26
 
22
- require 'todo-txt'
27
+ ``` ruby
28
+ require 'todo-txt'
23
29
 
24
- list = Todo::List.new "path/to/todo.txt"
30
+ list = Todo::List.new "path/to/todo.txt"
31
+ ```
25
32
 
26
- `Todo::List` subclasses `Array` so it has all of the standard methods that are available on an array. It is, basically, an array of `Todo::Task` items.
33
+ `Todo::List` subclasses `Array` so it has all of the standard methods that are
34
+ available on an array. It is, basically, an array of `Todo::Task` items.
27
35
 
28
36
  ### Filtering
29
37
 
30
- You can filter your todo list by priority, project, context or a combination of all three with ease.
38
+ You can filter your todo list by priority, project, context or a combination of
39
+ all three with ease.
31
40
 
32
- require 'todo-txt'
41
+ ``` ruby
42
+ require 'todo-txt'
33
43
 
34
- list = Todo::List.new "path/to/todo.txt"
44
+ list = Todo::List.new "path/to/todo.txt"
35
45
 
36
- list.by_priority "A"
37
- # => Contains a Todo::List object with only priority A tasks.
46
+ list.by_priority "A"
47
+ # => Contains a Todo::List object with only priority A tasks.
38
48
 
39
- list.by_context "@code"
40
- # => Returns a new Todo::List with only tasks that have a @code context.
49
+ list.by_context "@code"
50
+ # => Returns a new Todo::List with only tasks that have a @code context.
41
51
 
42
- list.by_project "+manhatten"
43
- # => Returns a new Todo::List with only tasks that are part of the
44
- +manhatten project (see what I did there?)
52
+ list.by_project "+manhatten"
53
+ # => Returns a new Todo::List with only tasks that are part of the
54
+ # +manhatten project (see what I did there?)
45
55
 
46
- # And you can combine these, like so
47
- list.by_project("+manhatten").by_priority("B")
56
+ # And you can combine these, like so
57
+ list.by_project("+manhatten").by_priority("B")
58
+ ```
48
59
 
49
60
  ## Todo::Task
50
61
 
51
- A `Todo::Task` object can be created from a standard task string if you don't want to use the `Todo::List` approach (though using `Todo::List` is recommended).
62
+ A `Todo::Task` object can be created from a standard task string if you don't
63
+ want to use the `Todo::List` approach (though using `Todo::List` is
64
+ recommended).
52
65
 
53
- require 'todo-txt'
66
+ ``` ruby
67
+ require 'todo-txt'
54
68
 
55
- task = Todo::Task.new "(A) This task is top priority! +project @context"
69
+ task = Todo::Task.new "(A) This task is top priority! +project @context"
56
70
 
57
- task.priority
58
- # => "A"
71
+ task.priority
72
+ # => "A"
59
73
 
60
- task.contexts
61
- # => ["@context"]
74
+ task.contexts
75
+ # => ["@context"]
62
76
 
63
- task.projects
64
- # => ["+project"]
77
+ task.projects
78
+ # => ["+project"]
65
79
 
66
- task.text
67
- # => "This task is top priority!"
80
+ task.text
81
+ # => "This task is top priority!"
68
82
 
69
- task.orig
70
- # => "(A) This task is top priority! +project @context"
83
+ task.orig
84
+ # => "(A) This task is top priority! +project @context"
85
+ ```
71
86
 
72
87
  ### Comparable
73
88
 
74
- The `Todo::Task` object includes the `Comparable` mixin. It compares with other tasks and sorts by priority in descending order.
89
+ The `Todo::Task` object includes the `Comparable` mixin. It compares with other
90
+ tasks and sorts by priority in descending order.
75
91
 
76
- task1 = Todo::Task.new "(A) Priority A."
77
- task2 = Todo::Task.new "(B) Priority B."
92
+ ``` ruby
93
+ task1 = Todo::Task.new "(A) Priority A."
94
+ task2 = Todo::Task.new "(B) Priority B."
78
95
 
79
- task1 > task2
80
- # => true
96
+ task1 > task2
97
+ # => true
81
98
 
82
- task1 == task2
83
- # => false
99
+ task1 == task2
100
+ # => false
84
101
 
85
- task2 > task1
86
- # => false
102
+ task2 > task1
103
+ # => false
104
+ ```
87
105
 
88
106
  Tasks without a priority will always be less than a task with a priority.
89
107
 
90
108
  # Requirements
91
109
 
92
- The todo-txt gem requires Ruby 1.9.2 or higher. It doesn't currently run on 1.8.7.
110
+ The todo-txt gem requires Ruby 1.9.2 or higher. It doesn't currently run on
111
+ 1.8.7.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
1
3
  require 'rspec/core/rake_task'
2
4
 
3
5
  task :default => [:test]
@@ -1,5 +1,7 @@
1
- # Require all files in the main lib directory
2
- Dir[File.dirname(__FILE__) + '/todo-txt/*.rb'].each do |file|
3
- require file
4
- end
1
+ lib = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
 
4
+ require 'logger'
5
+ require 'todo-txt/logger'
6
+ require 'todo-txt/list'
7
+ require 'todo-txt/task'
@@ -5,7 +5,7 @@ module Todo
5
5
  #
6
6
  # /home/sam/Dropbox/todo/todo.txt
7
7
  #
8
- # You would initialize this object like do:
8
+ # You would initialize this object like:
9
9
  #
10
10
  # list = Todo::List.new "/home/sam/Dropbox/todo/todo-txt"
11
11
  #
@@ -0,0 +1,21 @@
1
+ require 'logger'
2
+
3
+ module Todo
4
+ module Logger
5
+ def self.included base
6
+ base.extend(self)
7
+ end
8
+
9
+ def self.logger= new_logger
10
+ @@logger = new_logger
11
+ end
12
+
13
+ def self.logger
14
+ @@logger ||= ::Logger.new(STDOUT)
15
+ end
16
+
17
+ def logger
18
+ Todo::Logger.logger
19
+ end
20
+ end
21
+ end
@@ -3,6 +3,7 @@ require 'date'
3
3
  module Todo
4
4
  class Task
5
5
  include Comparable
6
+ include Todo::Logger
6
7
 
7
8
  # The regular expression used to match contexts.
8
9
  def self.contexts_regex
@@ -15,8 +16,8 @@ module Todo
15
16
  end
16
17
 
17
18
  # The regex used to match priorities.
18
- def self.priotity_regex
19
- /^\([A-Za-z]\)\s+/
19
+ def self.priority_regex
20
+ /(?:^|\s+)\(([A-Za-z])\)\s+/
20
21
  end
21
22
 
22
23
  # The regex used to match dates.
@@ -24,14 +25,34 @@ module Todo
24
25
  /(?:\s+|^)([0-9]{4}-[0-9]{2}-[0-9]{2})/
25
26
  end
26
27
 
28
+ # The regex used to match creation date.
29
+ def self.created_on_regex
30
+ /(?:^|-\d{2}\s|\)\s)(\d{4}-\d{2}-\d{2})\s/
31
+ end
32
+
27
33
  # The regex used to match completion.
28
34
  def self.done_regex
29
- /^x\s+/
35
+ /^x\s+(\d{4}-\d{2}-\d{2})\s+/
36
+ end
37
+
38
+ # The regex used to match due date.
39
+ def self.due_on_regex
40
+ /(?:due:)(\d{4}-\d{2}-\d{2})(?:\s+|$)/i
30
41
  end
31
42
 
32
- # Creates a new task. The argument that you pass in must be a string.
43
+ # Creates a new task. The argument that you pass in must be the string
44
+ # representation of a task.
45
+ #
46
+ # Example:
47
+ #
48
+ # task = Todo::Task.new("(A) A high priority task!")
33
49
  def initialize task
34
50
  @orig = task
51
+ @completed_on = get_completed_date #orig.scan(self.class.done_regex)[1] ||= nil
52
+ @priority, @created_on = orig_priority, orig_created_on
53
+ @due_on = get_due_on_date
54
+ @contexts ||= orig.scan(self.class.contexts_regex).map { |item| item.strip }
55
+ @projects ||= orig.scan(self.class.projects_regex).map { |item| item.strip }
35
56
  end
36
57
 
37
58
  # Returns the original content of the task.
@@ -40,9 +61,46 @@ module Todo
40
61
  #
41
62
  # task = Todo::Task.new "(A) @context +project Hello!"
42
63
  # task.orig #=> "(A) @context +project Hello!"
43
- def orig
44
- @orig
45
- end
64
+ attr_reader :orig
65
+
66
+ # Returns the task's creation date, if any.
67
+ #
68
+ # Example:
69
+ #
70
+ # task = Todo::Task.new "(A) 2012-03-04 Task."
71
+ # task.created_on
72
+ # #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
73
+ #
74
+ # Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
75
+ # format. Dates in any other format will be classed as malformed and this
76
+ # attribute will be nil.
77
+ attr_reader :created_on
78
+
79
+ # Returns the task's completion date if task is done.
80
+ #
81
+ # Example:
82
+ #
83
+ # task = Todo::Task.new "x 2012-03-04 Task."
84
+ # task.completed_on
85
+ # #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
86
+ #
87
+ # Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
88
+ # format. Dates in any other format will be classed as malformed and this
89
+ # attribute will be nil.
90
+ attr_reader :completed_on
91
+
92
+ # Returns the task's due date, if any.
93
+ #
94
+ # Example:
95
+ #
96
+ # task = Todo::Task.new "(A) This is a task. due:2012-03-04"
97
+ # task.due_on
98
+ # #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
99
+ #
100
+ # Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
101
+ # format. Dates in any other format will be classed as malformed and this
102
+ # attribute will be nil.
103
+ attr_reader :due_on
46
104
 
47
105
  # Returns the priority, if any.
48
106
  #
@@ -53,33 +111,23 @@ module Todo
53
111
  #
54
112
  # task = Todo::Task.new "Some task."
55
113
  # task.priority #=> nil
56
- def priority
57
- @priority ||= if orig =~ self.class.priotity_regex
58
- orig[1]
59
- else
60
- nil
61
- end
62
- end
114
+ attr_reader :priority
63
115
 
64
- # Retrieves an array of all the @context annotations.
116
+ # Returns an array of all the @context annotations.
65
117
  #
66
118
  # Example:
67
119
  #
68
120
  # task = Todo:Task.new "(A) @context Testing!"
69
121
  # task.context #=> ["@context"]
70
- def contexts
71
- @contexts ||= orig.scan(self.class.contexts_regex).map { |item| item.strip }
72
- end
122
+ attr_reader :contexts
73
123
 
74
- # Retrieves an array of all the +project annotations.
124
+ # Returns an array of all the +project annotations.
75
125
  #
76
126
  # Example:
77
127
  #
78
128
  # task = Todo:Task.new "(A) +test Testing!"
79
129
  # task.projects #=> ["+test"]
80
- def projects
81
- @projects ||= orig.scan(self.class.projects_regex).map { |item| item.strip }
82
- end
130
+ attr_reader :projects
83
131
 
84
132
  # Gets just the text content of the todo, without the priority, contexts
85
133
  # and projects annotations.
@@ -91,14 +139,15 @@ module Todo
91
139
  def text
92
140
  @text ||= orig.
93
141
  gsub(self.class.done_regex, '').
94
- gsub(self.class.date_regex, '').
95
- gsub(self.class.priotity_regex, '').
142
+ gsub(self.class.priority_regex, '').
143
+ gsub(self.class.created_on_regex, '').
96
144
  gsub(self.class.contexts_regex, '').
97
145
  gsub(self.class.projects_regex, '').
146
+ gsub(self.class.due_on_regex, '').
98
147
  strip
99
148
  end
100
149
 
101
- # Returns the date present in the task.
150
+ # Returns the task's creation date, if any.
102
151
  #
103
152
  # Example:
104
153
  #
@@ -109,32 +158,24 @@ module Todo
109
158
  # Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
110
159
  # format. Dates in any other format will be classed as malformed and this
111
160
  # method will return nil.
161
+ #
162
+ # Deprecated
112
163
  def date
113
- begin
114
- @date ||= Date.parse(orig.match(self.class.date_regex)[1])
115
- rescue
116
- @date = nil
117
- end
164
+ logger.warn("Task#date is deprecated, use created_on instead.")
165
+
166
+ @created_on
118
167
  end
119
168
 
120
- # Checks whether or not this task is overdue by comparing the task date to
121
- # the current date.
122
- #
123
- # If there is no date specified for this task, this method returns nil.
169
+ # Returns whether a task's due date is in the past.
124
170
  #
125
171
  # Example:
126
172
  #
127
- # task = Todo::Task.new "(A) 2012-03-04 Task."
173
+ # task = Todo::Task.new("This task is overdue! due:#{Date.today - 1}")
128
174
  # task.overdue?
129
175
  # #=> true
130
176
  def overdue?
131
- if date.nil?
132
- nil
133
- elsif date < Date.today
134
- true
135
- else
136
- false
137
- end
177
+ return true if !due_on.nil? && due_on < Date.today
178
+ false
138
179
  end
139
180
 
140
181
  # Returns if the task is done.
@@ -149,7 +190,79 @@ module Todo
149
190
  # task.done?
150
191
  # #=> false
151
192
  def done?
152
- @done ||= !(orig =~ self.class.done_regex).nil?
193
+ !@completed_on.nil?
194
+ end
195
+
196
+ # Completes the task on the current date.
197
+ #
198
+ # Example:
199
+ #
200
+ # task = Todo::Task.new "2012-12-08 Task."
201
+ # task.done?
202
+ # #=> false
203
+ #
204
+ # task.do!
205
+ # task.done?
206
+ # #=> true
207
+ # task.date
208
+ # #=> # the current date
209
+ def do!
210
+ @completed_on = Date.today
211
+ @priority = nil
212
+ end
213
+
214
+ # Marks the task as incomplete and resets its original due date.
215
+ #
216
+ # Example:
217
+ #
218
+ # task = Todo::Task.new "x 2012-12-08 Task."
219
+ # task.done?
220
+ # #=> true
221
+ #
222
+ # task.undo!
223
+ # task.done?
224
+ # #=> false
225
+ # task.date
226
+ # #=> # <Date: 2012-03-04 (4911981/2,0,2299161)>
227
+ def undo!
228
+ @completed_on = nil
229
+ @priority = orig_priority
230
+ end
231
+
232
+ # Toggles the task from complete to incomplete or vice versa.
233
+ #
234
+ # Example:
235
+ #
236
+ # task = Todo::Task.new "x 2012-12-08 Task."
237
+ # task.done?
238
+ # #=> true
239
+ #
240
+ # task.toggle!
241
+ # task.done?
242
+ # #=> false
243
+ #
244
+ # task.toggle!
245
+ # task.done?
246
+ # #=> true
247
+ def toggle!
248
+ done? ? undo! : do!
249
+ end
250
+
251
+ # Returns this task as a string.
252
+ #
253
+ # Example:
254
+ #
255
+ # task = Todo::Task.new "(A) 2012-12-08 Task"
256
+ # task.to_s
257
+ # #=> "(A) 2012-12-08 Task"
258
+ def to_s
259
+ priority_string = priority ? "(#{priority}) " : ""
260
+ done_string = done? ? "x #{completed_on} " : ""
261
+ created_on_string = created_on ? "#{created_on} " : ""
262
+ contexts_string = contexts.empty? ? "" : " #{contexts.join ' '}"
263
+ projects_string = projects.empty? ? "" : " #{projects.join ' '}"
264
+ due_on_string = due_on.nil? ? "" : " due:#{due_on}"
265
+ "#{done_string}#{priority_string}#{created_on_string}#{text}#{contexts_string}#{projects_string}#{due_on_string}"
153
266
  end
154
267
 
155
268
  # Compares the priorities of two tasks.
@@ -178,5 +291,36 @@ module Todo
178
291
  other_task.priority <=> self.priority
179
292
  end
180
293
  end
294
+
295
+ private
296
+
297
+ def orig_priority
298
+ @orig.match(self.class.priority_regex)[1] if @orig =~ self.class.priority_regex
299
+ end
300
+
301
+ def orig_created_on
302
+ begin
303
+ if @orig =~ self.class.created_on_regex
304
+ date = @orig.match self.class.created_on_regex
305
+ return Date.parse(date[1]) unless date.nil?
306
+ end
307
+ rescue; end
308
+ nil
309
+ end
310
+
311
+ def get_completed_date
312
+ begin
313
+ return Date.parse(self.class.done_regex.match(@orig)[1])
314
+ rescue; end
315
+ nil
316
+ end
317
+
318
+ def get_due_on_date
319
+ begin
320
+ return Date.parse(self.class.due_on_regex.match(@orig)[1])
321
+ rescue; end
322
+ nil
323
+ end
324
+
181
325
  end
182
326
  end
@@ -1,5 +1,6 @@
1
1
  require_relative '../spec_helper'
2
2
  require 'date'
3
+ require 'timecop'
3
4
 
4
5
  describe Todo::Task do
5
6
  it 'should recognise priorities' do
@@ -12,6 +13,11 @@ describe Todo::Task do
12
13
  task.priority.should == nil
13
14
  end
14
15
 
16
+ it 'should recognize priorities around dates' do
17
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project"
18
+ task.priority.should == "B"
19
+ end
20
+
15
21
  it 'should recognise contexts' do
16
22
  task = Todo::Task.new "Hello, world! @test"
17
23
  task.contexts.should == ["@test"]
@@ -38,7 +44,7 @@ describe Todo::Task do
38
44
  end
39
45
 
40
46
  it 'should be able to get just the text, no contexts etc.' do
41
- task = Todo::Task.new "x (B) 2012-03-04 This is a sweet task. @context +project"
47
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project"
42
48
  task.text.should == "This is a sweet task."
43
49
  end
44
50
 
@@ -68,37 +74,37 @@ describe Todo::Task do
68
74
 
69
75
  it 'should be able to recognise dates' do
70
76
  task = Todo::Task.new "(C) 2012-03-04 This has a date!"
71
- task.date.should == Date.parse("4th March 2012")
77
+ task.created_on.should == Date.parse("4th March 2012")
72
78
  end
73
79
 
74
80
  it 'should be able to recognise dates without priority' do
75
81
  task = Todo::Task.new "2012-03-04 This has a date!"
76
- task.date.should == Date.parse("4th March 2012")
82
+ task.created_on.should == Date.parse("4th March 2012")
77
83
  end
78
84
 
79
85
  it 'should return nil if no date is present' do
80
86
  task = Todo::Task.new "No date!"
81
- task.date.should be_nil
87
+ task.created_on.should be_nil
82
88
  end
83
89
 
84
90
  it 'should not recognise malformed dates' do
85
91
  task = Todo::Task.new "03-04-2012 This has a malformed date!"
86
- task.date.should be_nil
92
+ task.created_on.should be_nil
87
93
  end
88
94
 
89
95
  it 'should be able to tell if the task is overdue' do
90
96
  task = Todo::Task.new((Date.today - 1).to_s + " This task is overdue!")
91
- task.overdue?.should be_true
97
+ task.overdue?.should be_false
92
98
  end
93
99
 
94
- it 'should return nil on overdue? if there is no date' do
100
+ it 'should return false on overdue? if there is no date' do
95
101
  task = Todo::Task.new "No date!"
96
- task.overdue?.should be_nil
102
+ task.overdue?.should be_false
97
103
  end
98
104
 
99
105
  it 'should return nil on ridiculous date data' do
100
106
  task = Todo::Task.new "2012-56-99 This has a malformed date!"
101
- task.date.should be_nil
107
+ task.created_on.should be_nil
102
108
  end
103
109
 
104
110
  it 'should be able to recognise completed tasks' do
@@ -107,12 +113,192 @@ describe Todo::Task do
107
113
  end
108
114
 
109
115
  it 'should not recognize incomplete tasks as done' do
110
- task = Todo::Task.new "2012-12-08 This is ain't done!"
116
+ task = Todo::Task.new "2012-12-08 This ain't done!"
117
+ task.done?.should be_false
118
+ end
119
+
120
+ it 'should be completable' do
121
+ task = Todo::Task.new "2012-12-08 This ain't done!"
122
+ task.do!
123
+ task.done?.should be_true
124
+ end
125
+
126
+ it 'should be marked as incomplete' do
127
+ task = Todo::Task.new "x 2012-12-08 This is done!"
128
+ task.undo!
129
+ task.done?.should be_false
130
+ end
131
+
132
+ it 'should be marked as incomplete without any date' do
133
+ task = Todo::Task.new "x 2012-12-08 This is done!"
134
+ task.undo!
135
+ task.completed_on.should be_nil
136
+ task.created_on.should be_nil
137
+ end
138
+
139
+ it 'should be toggable' do
140
+ task = Todo::Task.new "2012-12-08 This ain't done!"
141
+ task.toggle!
142
+ task.done?.should be_true
143
+ task.toggle!
111
144
  task.done?.should be_false
112
145
  end
113
146
 
114
147
  it 'should be able to recognise completion dates' do
115
148
  task = Todo::Task.new "x 2012-12-08 This is done!"
116
- task.date.should == Date.parse("8th December 2012")
149
+ task.completed_on.should == Date.parse("8th December 2012")
150
+ end
151
+
152
+ it 'should remove the priority when calling Task#do!' do
153
+ task = Todo::Task.new "(A) Task"
154
+ task.do!
155
+ task.priority.should be_nil
156
+ end
157
+
158
+ it 'should reset to the original priority when calling Task#undo!' do
159
+ task = Todo::Task.new "(A) Task"
160
+ task.do!
161
+ task.undo!
162
+ task.priority.should == "A"
163
+ end
164
+
165
+ it 'should set the current completion dates when calling Task#do!' do
166
+ task = Todo::Task.new "2012-12-08 Task"
167
+ Timecop.freeze(2013, 12, 8) do
168
+ task.do!
169
+ task.completed_on.should == Date.parse("8th December 2013")
170
+ end
171
+ end
172
+
173
+ it 'should reset to the original due date when calling Task#undo!' do
174
+ task = Todo::Task.new "2012-12-08 Task"
175
+ Timecop.freeze(2013, 12, 8) do
176
+ task.do!
177
+ task.undo!
178
+ task.created_on.should == Date.parse("8th December 2012")
179
+ end
180
+ end
181
+
182
+ it 'should manage dates when calling Task#toggle!' do
183
+ task = Todo::Task.new "2012-12-08 This ain't done!"
184
+ Timecop.freeze(2013, 12, 8) do
185
+ task.toggle!
186
+ task.completed_on.should == Date.parse("8th December 2013")
187
+ task.created_on.should == Date.parse("8th December 2012")
188
+ task.toggle!
189
+ task.created_on.should == Date.parse("8th December 2012")
190
+ task.completed_on.should be_nil
191
+ end
192
+ end
193
+
194
+ it 'should convert to a string' do
195
+ task = Todo::Task.new "(A) 2012-12-08 My task @test +test2"
196
+ task.to_s.should == "(A) 2012-12-08 My task @test +test2"
197
+ end
198
+
199
+ it 'should keep track of the original string after changing the task' do
200
+ task = Todo::Task.new "(A) 2012-12-08 My task @test +test2"
201
+ Timecop.freeze(2013, 12, 8) do
202
+ task.do!
203
+ task.orig.should == "(A) 2012-12-08 My task @test +test2"
204
+ end
205
+ end
206
+
207
+ it 'should show be modifiable' do
208
+ task = Todo::Task.new "2012-12-08 My task @test +test2"
209
+ task.projects.clear
210
+ task.contexts << ["@test3"]
211
+ Timecop.freeze(2013, 12, 8) do
212
+ task.do!
213
+ task.to_s.should == "x 2013-12-08 2012-12-08 My task @test @test3"
214
+ end
215
+ end
216
+
217
+ it 'should be not done with missing date' do
218
+ task = Todo::Task.new "x This is not done"
219
+ task.done?.should be false
220
+ end
221
+
222
+ it 'should be not done with malformed date' do
223
+ task = Todo::Task.new "x 01-01-2013 This is not done"
224
+ task.done?.should be false
225
+ task.completed_on.should be nil
226
+ end
227
+
228
+ it 'should be not done with an invalid date' do
229
+ task = Todo::Task.new "x 2013-02-31 This is not done"
230
+ task.done?.should be false
231
+ task.completed_on.should be nil
232
+ end
233
+
234
+ it 'should be done on 2013-04-22' do
235
+ task = Todo::Task.new "x 2013-04-22 This is really done"
236
+ task.done?.should be true
237
+ task.completed_on.should == Date.parse('22th April 2013')
238
+ end
239
+
240
+ its 'should have a due date' do
241
+ task = Todo::Task.new '(A) this task has due date due:2013-12-22'
242
+ task.due_on.should_not be_nil
243
+ end
244
+
245
+ it 'should due on 2013-12-22' do
246
+ task = Todo::Task.new '(A) this task has due date due:2013-12-22'
247
+ task.due_on.should == Date.parse('22th December 2013')
248
+ end
249
+
250
+ it 'should not be overdue on 2013-12-01' do
251
+ task = Todo::Task.new '(A) this task has due date due:2013-12-22'
252
+ Timecop.freeze(2013, 12, 01) do
253
+ task.overdue?.should be_false
254
+ end
255
+ end
256
+
257
+ it 'should be overdue on 2013-12-23' do
258
+ task = Todo::Task.new '(A) this task has due date due:2013-12-22'
259
+ Timecop.freeze(2013, 12, 23) do
260
+ task.overdue?.should be_true
261
+ end
262
+ end
263
+
264
+ it 'should be able to get just the text, no due date etc.' do
265
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project"
266
+ task.text.should == "This is a sweet task."
267
+ end
268
+
269
+ it 'should convert to a string with due date' do
270
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-01-01 +project"
271
+ task.to_s.should == "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context +project due:2012-01-01"
272
+ end
273
+
274
+ it 'should have no due date with malformed date' do
275
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:01-01-2012 +project"
276
+ task.due_on.should be_nil
277
+ end
278
+
279
+ it 'should have no due date with invalid date' do
280
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
281
+ task.due_on.should be_nil
282
+ end
283
+
284
+ it 'should recognize DUE:2013-12-22 (case insensitive)' do
285
+ task = Todo::Task.new '(A) this task has due date DUE:2013-12-22'
286
+ task.due_on.should == Date.parse('22th December 2013')
287
+ end
288
+
289
+ it 'should have a logger' do
290
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
291
+ task.logger.should_not be nil
292
+ end
293
+
294
+ it 'should call @logger.warn if #date called as deprecated method' do
295
+ logger = double(Logger)
296
+ Todo::Logger.logger = logger
297
+
298
+ task = Todo::Task.new "x 2012-09-11 (B) 2012-03-04 This is a sweet task. @context due:2012-02-31 +project"
299
+ error_message = 'Task#date is deprecated, use created_on instead.'
300
+
301
+ logger.should_receive(:warn).with(error_message)
302
+ task.date
117
303
  end
118
304
  end
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{todo-txt}
3
- s.version = "0.3.1"
4
- s.date = %q{2012-03-31}
3
+ s.version = "0.4"
5
4
  s.authors = ["Sam Rose"]
6
5
  s.email = %q{samwho@lbak.co.uk}
7
6
  s.summary = %q{A client library for parsing todo.txt files.}
@@ -11,5 +10,5 @@ Gem::Specification.new do |s|
11
10
  s.license = 'GPL-2'
12
11
 
13
12
  # Add all files to the files parameter.
14
- s.files = `git ls-files`.split /\n/
13
+ s.files = `git ls-files`.split(/\n/)
15
14
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo-txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: '0.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sam Rose
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-31 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Allows for simple parsing of todo.txt files, as per Gina Trapani's todo.txt
15
14
  project.
@@ -28,6 +27,7 @@ files:
28
27
  - Rakefile
29
28
  - lib/todo-txt.rb
30
29
  - lib/todo-txt/list.rb
30
+ - lib/todo-txt/logger.rb
31
31
  - lib/todo-txt/task.rb
32
32
  - spec/data/todo.txt
33
33
  - spec/spec_helper.rb
@@ -37,26 +37,25 @@ files:
37
37
  homepage: http://github.com/samwho/todo-txt-gem
38
38
  licenses:
39
39
  - GPL-2
40
+ metadata: {}
40
41
  post_install_message:
41
42
  rdoc_options: []
42
43
  require_paths:
43
44
  - lib
44
45
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
46
  requirements:
47
- - - ! '>='
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: 1.9.2
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
51
  requirements:
53
- - - ! '>='
52
+ - - '>='
54
53
  - !ruby/object:Gem::Version
55
54
  version: '0'
56
55
  requirements: []
57
56
  rubyforge_project:
58
- rubygems_version: 1.8.24
57
+ rubygems_version: 2.0.3
59
58
  signing_key:
60
- specification_version: 3
59
+ specification_version: 4
61
60
  summary: A client library for parsing todo.txt files.
62
61
  test_files: []