todo-txt 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/gems/todo-txt-0.1.1.gem +0 -0
- data/lib/todo-txt/task.rb +46 -0
- data/spec/data/todo.txt +4 -0
- data/spec/todo-txt/task_spec.rb +36 -0
- data/todo-txt.gemspec +3 -2
- metadata +10 -8
data/.gemtest
ADDED
File without changes
|
Binary file
|
data/lib/todo-txt/task.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module Todo
|
2
4
|
class Task
|
3
5
|
include Comparable
|
@@ -17,6 +19,11 @@ module Todo
|
|
17
19
|
/^\([A-Za-z]\)\s+/
|
18
20
|
end
|
19
21
|
|
22
|
+
# The regex used to match dates.
|
23
|
+
def self.date_regex
|
24
|
+
/(?:\([A-Za-z]\)\s+|^)([0-9]{4}-[0-9]{2}-[0-9]{2})/
|
25
|
+
end
|
26
|
+
|
20
27
|
# Creates a new task. The argument that you pass in must be a string.
|
21
28
|
def initialize task
|
22
29
|
@orig = task
|
@@ -84,6 +91,45 @@ module Todo
|
|
84
91
|
strip
|
85
92
|
end
|
86
93
|
|
94
|
+
# Returns the date present in the task.
|
95
|
+
#
|
96
|
+
# Example:
|
97
|
+
#
|
98
|
+
# task = Todo::Task.new "(A) 2012-03-04 Task."
|
99
|
+
# task.date
|
100
|
+
# #=> <Date: 2012-03-04 (4911981/2,0,2299161)>
|
101
|
+
#
|
102
|
+
# Dates _must_ be in the YYYY-MM-DD format as specified in the todo.txt
|
103
|
+
# format. Dates in any other format will be classed as malformed and this
|
104
|
+
# method will return nil.
|
105
|
+
def date
|
106
|
+
begin
|
107
|
+
@date ||= Date.parse(orig.match(self.class.date_regex)[1])
|
108
|
+
rescue
|
109
|
+
@date = nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Checks whether or not this task is overdue by comparing the task date to
|
114
|
+
# the current date.
|
115
|
+
#
|
116
|
+
# If there is no date specified for this task, this method returns nil.
|
117
|
+
#
|
118
|
+
# Example:
|
119
|
+
#
|
120
|
+
# task = Todo::Task.new "(A) 2012-03-04 Task."
|
121
|
+
# task.overdue?
|
122
|
+
# #=> true
|
123
|
+
def overdue?
|
124
|
+
if date.nil?
|
125
|
+
nil
|
126
|
+
elsif date < Date.today
|
127
|
+
true
|
128
|
+
else
|
129
|
+
false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
87
133
|
# Compares the priorities of two tasks.
|
88
134
|
#
|
89
135
|
# Example:
|
data/spec/data/todo.txt
CHANGED
@@ -3,3 +3,7 @@
|
|
3
3
|
@context Give it some context.
|
4
4
|
Just a POD: Plain old task.
|
5
5
|
(C) +project @context This one has it all!
|
6
|
+
(C) 2012-02-03 This one has a date!
|
7
|
+
(B) 2012-03-04 +project @context This one has a date and a context AND a project!
|
8
|
+
2012-04-03 This one has no priority and a date.
|
9
|
+
03-04-2012 This one has a malformed date.
|
data/spec/todo-txt/task_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
+
require 'date'
|
2
3
|
|
3
4
|
describe Todo::Task do
|
4
5
|
it 'should recognise priorities' do
|
@@ -64,4 +65,39 @@ describe Todo::Task do
|
|
64
65
|
assertion = task1 == task2
|
65
66
|
assertion.should == true
|
66
67
|
end
|
68
|
+
|
69
|
+
it 'should be able to recognise dates' do
|
70
|
+
task = Todo::Task.new "(C) 2012-03-04 This has a date!"
|
71
|
+
task.date.should == Date.parse("4th March 2012")
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should be able to recognise dates without priority' do
|
75
|
+
task = Todo::Task.new "2012-03-04 This has a date!"
|
76
|
+
task.date.should == Date.parse("4th March 2012")
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return nil if no date is present' do
|
80
|
+
task = Todo::Task.new "No date!"
|
81
|
+
task.date.should be_nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should not recognise malformed dates' do
|
85
|
+
task = Todo::Task.new "03-04-2012 This has a malformed date!"
|
86
|
+
task.date.should be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should be able to tell if the task is overdue' do
|
90
|
+
task = Todo::Task.new((Date.today - 1).to_s + " This task is overdue!")
|
91
|
+
task.overdue?.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return nil on overdue? if there is no date' do
|
95
|
+
task = Todo::Task.new "No date!"
|
96
|
+
task.overdue?.should be_nil
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should return nil on ridiculous date data' do
|
100
|
+
task = Todo::Task.new "2012-56-99 This has a malformed date!"
|
101
|
+
task.date.should be_nil
|
102
|
+
end
|
67
103
|
end
|
data/todo-txt.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{todo-txt}
|
3
|
-
s.version = "0.
|
4
|
-
s.date = %q{
|
3
|
+
s.version = "0.2"
|
4
|
+
s.date = %q{2012-03-31}
|
5
5
|
s.authors = ["Sam Rose"]
|
6
6
|
s.email = %q{samwho@lbak.co.uk}
|
7
7
|
s.summary = %q{A client library for parsing todo.txt files.}
|
@@ -13,4 +13,5 @@ Gem::Specification.new do |s|
|
|
13
13
|
# Add all files to the files parameter.
|
14
14
|
s.files = []
|
15
15
|
Dir["**/*.*"].each { |path| s.files.push path }
|
16
|
+
s.files.push ".gemtest"
|
16
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: todo-txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-31 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Allows for simple parsing of todo.txt files, as per Gina Trapani's todo.txt
|
15
15
|
project.
|
@@ -18,16 +18,18 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- lib/todo-txt/list.rb
|
22
|
+
- lib/todo-txt/task.rb
|
23
|
+
- lib/todo-txt.rb
|
24
|
+
- gems/todo-txt-0.1.1.gem
|
25
|
+
- gems/todo-txt-0.1.gem
|
21
26
|
- README.md
|
22
27
|
- spec/todo-txt/list_spec.rb
|
23
28
|
- spec/todo-txt/task_spec.rb
|
24
|
-
- spec/data/todo.txt
|
25
29
|
- spec/spec_helper.rb
|
26
|
-
-
|
30
|
+
- spec/data/todo.txt
|
27
31
|
- todo-txt.gemspec
|
28
|
-
-
|
29
|
-
- lib/todo-txt/task.rb
|
30
|
-
- lib/todo-txt.rb
|
32
|
+
- .gemtest
|
31
33
|
homepage: http://github.com/samwho/todo-txt-gem
|
32
34
|
licenses:
|
33
35
|
- GPL-2
|
@@ -49,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
51
|
version: '0'
|
50
52
|
requirements: []
|
51
53
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.8.
|
54
|
+
rubygems_version: 1.8.15
|
53
55
|
signing_key:
|
54
56
|
specification_version: 3
|
55
57
|
summary: A client library for parsing todo.txt files.
|