todotxt-rb 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +8 -0
- data/lib/todotxt.rb +3 -0
- data/lib/todotxt/list.rb +47 -0
- data/lib/todotxt/relation.rb +9 -0
- data/lib/todotxt/task.rb +67 -0
- data/lib/todotxt/version.rb +3 -0
- data/spec/spec_helper.rb +89 -0
- data/spec/todotxt/list_spec.rb +83 -0
- data/spec/todotxt/task_spec.rb +187 -0
- data/todotxt-rb.gemspec +24 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73a35cf97fa70e3ddaaeb179c81288391987cb5a
|
4
|
+
data.tar.gz: 0e47805c962a92b9da26773f3291b0bcaec2ea47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bc58ddaff5ed0a0f9301901f7a88e050575593bfe7cc37dd6fb9d3657aee08236fe2a37d7cd76a00d59c8dfde19b6407ec83517946ca6f0bf54693fe4e74f8a
|
7
|
+
data.tar.gz: b99aa6fcba603575cd341bd54daa94ca815ff3c2bb44fd071274f7ce28882733cb62962435ed60b65cc501e1f3665371c4302c06b48be17321165caa5270a99e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Tyler Dooling
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# TodoTxt
|
2
|
+
|
3
|
+
[](https://travis-ci.org/tylerdooling/todotxt-rb)
|
5
|
+
|
6
|
+
TodoTxt is a small ruby libary for easily interacting with [Todo.txt](http://todotxt.com) formatted files.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'todotxt'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install todotxt
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Lists
|
27
|
+
Lists can be loaded from a file or instantiated in an empty state. They
|
28
|
+
behave likes arrays and the can be written to a file when you're
|
29
|
+
finished.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
# Load a list from a file
|
33
|
+
file = File.new('your_todos_file')
|
34
|
+
list = TodoTxt::List.from_file(file) #=> accepts any IO
|
35
|
+
|
36
|
+
# Utilize enumerable behaviours
|
37
|
+
list.each { |todo| ... }
|
38
|
+
list.map { |todo| ... }
|
39
|
+
list.select { |todo| ... }
|
40
|
+
|
41
|
+
# Adding tasks
|
42
|
+
list.push task
|
43
|
+
list << task
|
44
|
+
|
45
|
+
# Deleting a task
|
46
|
+
list.delete task
|
47
|
+
|
48
|
+
# Persist to list to a file
|
49
|
+
list.to_file(file) #=> accepts any IO
|
50
|
+
```
|
51
|
+
|
52
|
+
### Tasks
|
53
|
+
Tasks are nothing more than a simple wrapper around a struct. They can
|
54
|
+
be parsed from an existing [Todo.txt formatted](https://github.com/ginatrapani/todo.txt-cli/wiki/The-Todo.txt-Format) task or created from scratch.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# Parse a task
|
58
|
+
TodoTxt::Task.parse '(A) Call Mom +Family +PeaceLoveAndHappiness @iphone'
|
59
|
+
# Create a blank task
|
60
|
+
TodoTxt::Task.new
|
61
|
+
# Create a task with attributes
|
62
|
+
TodoTxt::Task.new text: 'Call Mom'
|
63
|
+
|
64
|
+
# Complete a task
|
65
|
+
task.complete!
|
66
|
+
```
|
67
|
+
|
68
|
+
## Alternatives
|
69
|
+
- [todo-txt-gem](https://github.com/samwho/todo-txt-gem)
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it ([https://github.com/tylerdooling/todotxt-rb/fork](https://github.com/tylerdooling/todotxt-rb/fork))
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/todotxt.rb
ADDED
data/lib/todotxt/list.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'todotxt/task'
|
3
|
+
|
4
|
+
module TodoTxt
|
5
|
+
# Lists can be loaded from a file or instantiated in an empty state. They
|
6
|
+
# behave likes arrays and the can be written to a file when you're
|
7
|
+
# finished.
|
8
|
+
class List
|
9
|
+
include Enumerable
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
def_delegators :tasks, *(Array.instance_methods)
|
13
|
+
|
14
|
+
# Parses a Todo.txt formatted file
|
15
|
+
# @param [IO] file an IO input
|
16
|
+
def self.from_file(file)
|
17
|
+
tasks = file.readlines.map { |line|
|
18
|
+
chomped = line.chomp
|
19
|
+
Task.parse(chomped) unless chomped.empty?
|
20
|
+
}.compact
|
21
|
+
new tasks
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [Array<Task>] an array of tasks
|
25
|
+
def initialize(tasks = [])
|
26
|
+
@tasks = tasks
|
27
|
+
end
|
28
|
+
|
29
|
+
def each
|
30
|
+
tasks.each { |t| yield t }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
map(&:to_s).join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Writes the list to a file
|
38
|
+
# @param [IO] file an IO object
|
39
|
+
def to_file(file)
|
40
|
+
file.write(to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :tasks
|
46
|
+
end
|
47
|
+
end
|
data/lib/todotxt/task.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'todotxt/relation'
|
3
|
+
|
4
|
+
module TodoTxt
|
5
|
+
# A basic Todo.txt task
|
6
|
+
# :priority The task priority
|
7
|
+
# :created_at The created date for the task
|
8
|
+
# :text The text for the task
|
9
|
+
# :completed_at The completed date for the task
|
10
|
+
# :contexts The contexts mentioned in the task
|
11
|
+
# :projects The projects mentioned in the task
|
12
|
+
Task = Relation.new(:priority, :created_at, :text, :completed_at) do
|
13
|
+
PROJECTS = /(?:^| )\+(\S+)/
|
14
|
+
CONTEXTS = /(?:^| )@(\S+)/
|
15
|
+
COMPLETED_TASK = /^x (\d\d\d\d-\d\d-\d\d) (?:(\d\d\d\d-\d\d-\d\d) |)(.+)/
|
16
|
+
PRIORITIZED_TASK = /^(?:\(([ABC])\) |)(?:(\d\d\d\d-\d\d-\d\d) |)(.+)/
|
17
|
+
|
18
|
+
# Parses an existing Todo.txt task from a string
|
19
|
+
# @param [String] raw the task string
|
20
|
+
def self.parse(raw)
|
21
|
+
args = {}
|
22
|
+
args[:text] = raw
|
23
|
+
if raw =~ COMPLETED_TASK
|
24
|
+
args[:completed_at] = DateTime.parse($1)
|
25
|
+
args[:created_at] = DateTime.parse($2) if $2
|
26
|
+
args[:text] = $3
|
27
|
+
else
|
28
|
+
raw =~ PRIORITIZED_TASK
|
29
|
+
args[:priority] = $1
|
30
|
+
args[:created_at] = DateTime.parse($2) if $2
|
31
|
+
args[:text] = $3
|
32
|
+
end
|
33
|
+
new(args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def completed?
|
37
|
+
!!completed_at
|
38
|
+
end
|
39
|
+
|
40
|
+
# Completes a task and sets the required dependencies
|
41
|
+
def complete!
|
42
|
+
self.completed_at ||= Time.now
|
43
|
+
end
|
44
|
+
|
45
|
+
# Marks a completed task as not complete and sets the required dependencies
|
46
|
+
def revive!
|
47
|
+
self.completed_at = nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def contexts
|
51
|
+
Array(text.to_s.scan(CONTEXTS)).flatten
|
52
|
+
end
|
53
|
+
|
54
|
+
def projects
|
55
|
+
Array(text.to_s.scan(PROJECTS)).flatten
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
''.tap do |s|
|
60
|
+
s << "x #{completed_at.strftime('%Y-%m-%d')} " if completed?
|
61
|
+
s << "(#{priority}) " if priority
|
62
|
+
s << "#{created_at.strftime('%Y-%m-%d')} " if created_at
|
63
|
+
s << text.to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
=begin
|
44
|
+
# These two settings work together to allow you to limit a spec run
|
45
|
+
# to individual examples or groups you care about by tagging them with
|
46
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
+
# get run.
|
48
|
+
config.filter_run :focus
|
49
|
+
config.run_all_when_everything_filtered = true
|
50
|
+
|
51
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
+
config.disable_monkey_patching!
|
57
|
+
|
58
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
59
|
+
# be too noisy due to issues in dependencies.
|
60
|
+
config.warnings = true
|
61
|
+
|
62
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
+
# file, and it's useful to allow more verbose output when running an
|
64
|
+
# individual spec file.
|
65
|
+
if config.files_to_run.one?
|
66
|
+
# Use the documentation formatter for detailed output,
|
67
|
+
# unless a formatter has already been configured
|
68
|
+
# (e.g. via a command-line flag).
|
69
|
+
config.default_formatter = 'doc'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Print the 10 slowest examples and example groups at the
|
73
|
+
# end of the spec run, to help surface which specs are running
|
74
|
+
# particularly slow.
|
75
|
+
config.profile_examples = 10
|
76
|
+
|
77
|
+
# Run specs in random order to surface order dependencies. If you find an
|
78
|
+
# order dependency and want to debug it, you can fix the order by providing
|
79
|
+
# the seed, which is printed after each run.
|
80
|
+
# --seed 1234
|
81
|
+
config.order = :random
|
82
|
+
|
83
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
+
# test failures related to randomization by passing the same `--seed` value
|
86
|
+
# as the one that triggered the failure.
|
87
|
+
Kernel.srand config.seed
|
88
|
+
=end
|
89
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'todotxt/list'
|
3
|
+
|
4
|
+
module TodoTxt
|
5
|
+
describe List do
|
6
|
+
it 'is empty by default' do
|
7
|
+
expect(List.new).to be_empty
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'accepts a list of tasks' do
|
11
|
+
tasks = [double]
|
12
|
+
expect(List.new(tasks)).to_not be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'is enumerable' do
|
16
|
+
tasks = [double]
|
17
|
+
list = List.new(tasks)
|
18
|
+
expect { |block| list.each(&block) }.to yield_with_args(*tasks)
|
19
|
+
expect { |block| list.map(&block) }.to yield_with_args(*tasks)
|
20
|
+
expect { |block| list.select(&block) }.to yield_with_args(*tasks)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'from_file' do
|
24
|
+
let(:tasks) {
|
25
|
+
<<-TASKS
|
26
|
+
(A) Call Mom +Family +PeaceLoveAndHappiness @iphone @phone
|
27
|
+
Email SoAndSo at soandso@example.com
|
28
|
+
Learn how to add 2+2
|
29
|
+
x 2011-03-03 Call Mom
|
30
|
+
x 2011-03-03 2011-03-02 Call Mom
|
31
|
+
Call Mom
|
32
|
+
X 2011-03-02 Call Mom
|
33
|
+
X Really gotta call Mom (A) @phone @someday
|
34
|
+
TASKS
|
35
|
+
}
|
36
|
+
around do |example|
|
37
|
+
`echo "#{tasks}" > /tmp/test-todo-task-list.txt`
|
38
|
+
example.run
|
39
|
+
`rm /tmp/test-todo-task-list.txt`
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when the file is empty' do
|
43
|
+
it 'parses an empty list of tasks' do
|
44
|
+
`touch /tmp/test-todo-task-list-empty.txt`
|
45
|
+
expect(List.from_file(File.new('/tmp/test-todo-task-list-empty.txt')).size).to be(0)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the file has tasks' do
|
50
|
+
it 'parses a list of tasks from a file' do
|
51
|
+
expect(List.from_file(File.new('/tmp/test-todo-task-list.txt')).size).to be(8)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'to_file' do
|
57
|
+
let(:tasks) {
|
58
|
+
<<-TASKS
|
59
|
+
(A) Call Mom +Family +PeaceLoveAndHappiness @iphone @phone
|
60
|
+
Email SoAndSo at soandso@example.com
|
61
|
+
Learn how to add 2+2
|
62
|
+
x 2011-03-03 Call Mom
|
63
|
+
x 2011-03-03 2011-03-02 Call Mom
|
64
|
+
Call Mom
|
65
|
+
X 2011-03-02 Call Mom
|
66
|
+
X Really gotta call Mom (A) @phone @someday
|
67
|
+
TASKS
|
68
|
+
}
|
69
|
+
before do
|
70
|
+
`rm /tmp/test-todo-task-list.txt`
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'writes the same content it reads (sanity check)' do
|
74
|
+
input = StringIO.new(tasks)
|
75
|
+
output = StringIO.new
|
76
|
+
list = List.from_file(input)
|
77
|
+
list.to_file(output)
|
78
|
+
output.rewind
|
79
|
+
expect(output.read).to eq(tasks.chomp)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'todotxt/task'
|
3
|
+
|
4
|
+
module TodoTxt
|
5
|
+
describe Task do
|
6
|
+
describe 'complete!' do
|
7
|
+
let(:todo) { Task.new }
|
8
|
+
|
9
|
+
it 'marks the task as completed' do
|
10
|
+
expect(todo).to_not be_completed
|
11
|
+
todo.complete!
|
12
|
+
expect(todo).to be_completed
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'marks the task with a completed_at date' do
|
16
|
+
expect(todo.completed_at).to be_nil
|
17
|
+
todo.complete!
|
18
|
+
expect(todo.completed_at).to be
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'revive!' do
|
23
|
+
let(:todo) { Task.new }
|
24
|
+
before { todo.complete! }
|
25
|
+
|
26
|
+
it 'marks the task as not completed' do
|
27
|
+
expect(todo).to be_completed
|
28
|
+
todo.revive!
|
29
|
+
expect(todo).to_not be_completed
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'removes the completed_at date' do
|
33
|
+
expect(todo.completed_at).to be
|
34
|
+
todo.revive!
|
35
|
+
expect(todo.completed_at).to be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'parse' do
|
40
|
+
context 'completed' do
|
41
|
+
let(:complete) { [
|
42
|
+
'x 2011-03-03 Call Mom',
|
43
|
+
'x 2011-03-03 2011-03-02 Call Mom'
|
44
|
+
] }
|
45
|
+
|
46
|
+
let(:incomplete) { [
|
47
|
+
'Call Mom',
|
48
|
+
'X 2011-03-02 Call Mom',
|
49
|
+
'X Really gotta call Mom (A) @phone @someday',
|
50
|
+
] }
|
51
|
+
|
52
|
+
it 'parses completed tasks' do
|
53
|
+
complete.each do |t|
|
54
|
+
expect(Task.parse(t)).to be_completed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'parses incomplete tasks' do
|
59
|
+
incomplete.each do |t|
|
60
|
+
expect(Task.parse(t)).to_not be_completed
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'completed_at' do
|
66
|
+
let(:complete) { [
|
67
|
+
'x 2011-03-03 Call Mom',
|
68
|
+
'x 2011-03-03 2011-03-02 Call Mom'
|
69
|
+
] }
|
70
|
+
|
71
|
+
let(:incomplete) { [
|
72
|
+
'Call Mom',
|
73
|
+
'X 2011-03-02 Call Mom',
|
74
|
+
'X Really gotta call Mom (A) @phone @someday',
|
75
|
+
] }
|
76
|
+
|
77
|
+
it 'parses completed_at for completed tasks' do
|
78
|
+
complete.each do |t|
|
79
|
+
expect(Task.parse(t).completed_at).to eq(DateTime.parse('2011-03-03'))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'ignores completed_at for incomplete tasks' do
|
84
|
+
incomplete.each do |t|
|
85
|
+
expect(Task.parse(t).completed_at).to be_nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'priority' do
|
91
|
+
let(:tasks_with) { [
|
92
|
+
'(A) Call Mom',
|
93
|
+
'(A) 2011-03-02 Call Mom'
|
94
|
+
] }
|
95
|
+
|
96
|
+
let(:tasks_without) { [
|
97
|
+
'Call Mom',
|
98
|
+
'2011-03-02 Call Mom',
|
99
|
+
'Really gotta call Mom (A) @phone @someday',
|
100
|
+
'(b) Get back to the boss',
|
101
|
+
'(B)->Submit TPS report'
|
102
|
+
] }
|
103
|
+
|
104
|
+
it 'parses valid priority' do
|
105
|
+
tasks_with.each do |t|
|
106
|
+
expect(Task.parse(t).priority).to eq('A')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'ignores invalid priority' do
|
111
|
+
tasks_without.each do |t|
|
112
|
+
expect(Task.parse(t).priority).to be_nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'created_at' do
|
118
|
+
let(:tasks_with) { [
|
119
|
+
'2011-03-02 Document +TodoTxt task format',
|
120
|
+
'(A) 2011-03-02 Call Mom'
|
121
|
+
] }
|
122
|
+
|
123
|
+
let(:tasks_without) { [
|
124
|
+
'(A) Call Mom 2011-03-02'
|
125
|
+
] }
|
126
|
+
|
127
|
+
it 'parses valid created_at' do
|
128
|
+
tasks_with.each do |t|
|
129
|
+
expect(Task.parse(t).created_at).to eq(DateTime.parse('2011-03-02'))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'ignores invalid created_at' do
|
134
|
+
tasks_without.each do |t|
|
135
|
+
expect(Task.parse(t).created_at).to be_nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'context and project' do
|
141
|
+
let(:tasks_with) { [
|
142
|
+
'(A) Call Mom +Family +PeaceLoveAndHappiness @iphone @phone'
|
143
|
+
] }
|
144
|
+
|
145
|
+
let(:tasks_without) { [
|
146
|
+
'Email SoAndSo at soandso@example.com',
|
147
|
+
'Learn how to add 2+2'
|
148
|
+
] }
|
149
|
+
|
150
|
+
it 'parses valid context' do
|
151
|
+
tasks_with.each do |t|
|
152
|
+
expect(Task.parse(t).contexts).to eq(%w(iphone phone))
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'parses valid project' do
|
157
|
+
tasks_with.each do |t|
|
158
|
+
expect(Task.parse(t).projects).to eq(%w(Family PeaceLoveAndHappiness))
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'ignores invalid context' do
|
163
|
+
tasks_without.each do |t|
|
164
|
+
expect(Task.parse(t).contexts).to be_empty
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'ignores invalid project' do
|
169
|
+
tasks_without.each do |t|
|
170
|
+
expect(Task.parse(t).projects).to be_empty
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'parses text' do
|
176
|
+
text = 'Call Mom +Family +PeaceLoveAndHappiness @iphone @phone'
|
177
|
+
[
|
178
|
+
"(A) 2011-03-02 #{text}",
|
179
|
+
"(A) #{text}",
|
180
|
+
text
|
181
|
+
].each do |raw|
|
182
|
+
expect(Task.parse(raw).text).to eq(text)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
data/todotxt-rb.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'todotxt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "todotxt-rb"
|
8
|
+
spec.version = TodoTxt::VERSION
|
9
|
+
spec.authors = ["Tyler Dooling"]
|
10
|
+
spec.email = ["me@tylerdooling.com"]
|
11
|
+
spec.summary = %q{A ruby library for interacting with Todo.txt formatted files.}
|
12
|
+
spec.description = %q{A ruby library for interacting with Todo.txt formatted files.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: todotxt-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tyler Dooling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A ruby library for interacting with Todo.txt formatted files.
|
56
|
+
email:
|
57
|
+
- me@tylerdooling.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/todotxt.rb
|
70
|
+
- lib/todotxt/list.rb
|
71
|
+
- lib/todotxt/relation.rb
|
72
|
+
- lib/todotxt/task.rb
|
73
|
+
- lib/todotxt/version.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- spec/todotxt/list_spec.rb
|
76
|
+
- spec/todotxt/task_spec.rb
|
77
|
+
- todotxt-rb.gemspec
|
78
|
+
homepage: ''
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.2.2
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: A ruby library for interacting with Todo.txt formatted files.
|
102
|
+
test_files:
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/todotxt/list_spec.rb
|
105
|
+
- spec/todotxt/task_spec.rb
|