todo_txt_rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'guard'
5
+ gem 'guard-rspec'
6
+ gem 'rspec'
7
+ gem 'rb-fsevent', '~> 0.9.1'
8
+ gem 'terminal-notifier-guard'
9
+ gem 'fakefs'
10
+ end
11
+
12
+ # Specify your gem's dependencies in todo_txt_rb.gemspec
13
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chris Lee
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,29 @@
1
+ # TodoTxtRb
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'todo_txt_rb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install todo_txt_rb
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/todo_rb ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/todo_txt_rb'
3
+ require 'yaml'
4
+ include TodoTxt
5
+
6
+ if File.exists?(Dir.home.to_s + '/.todocfg.yml')
7
+ todo_txt = YAML::load(File.open(Dir.home.to_s + '/.todocfg.yml'))["todo_file_location"]
8
+ todolist = TodoTxt::List.new todo_txt
9
+ end
10
+
11
+
12
+ case ARGV[0]
13
+ when "list"
14
+ TodoTxt::print_todo_list todolist
15
+ when "add"
16
+ todolist.add_todo ARGV.drop(1).join(" ")
17
+ when "rm"
18
+ todolist.remove_todo ARGV[1].to_i
19
+ when "do"
20
+ todolist.complete_todo ARGV[1].to_i
21
+ when "replace"
22
+ todolist.edit_todo ARGV[1].to_i, ARGV.drop(2).join(" ")
23
+ when "listproj"
24
+ puts todolist.list_projects.join(", ")
25
+ when "listcontext"
26
+ puts todolist.list_contexts.join(", ")
27
+ when "--init"
28
+ TodoTxt::init_config
29
+ else
30
+ puts "\n\nAvailable Commands:"
31
+ puts "todo_rb add 'Thing you need to do'"
32
+ puts " Adds 'Thing you need to do' to your todo.txt file"
33
+ puts ""
34
+ puts "todo_rb list"
35
+ puts " Lists your active todo's from your todo.txt file"
36
+ puts ""
37
+ puts "todo_rb rm <todo number>"
38
+ puts " Removes a todo based on the todo number received"
39
+ puts ""
40
+ puts "todo_rb do <todo number>"
41
+ puts " Marks a todo complete"
42
+ puts ""
43
+ puts "todo_rb replace <todo number> 'New thing you need to do'"
44
+ puts " Replaces the Todo with a new todo"
45
+ puts ""
46
+ puts "todo_rb listproj"
47
+ puts " lists all active projects"
48
+ puts ""
49
+ puts "todo_rb listcontext"
50
+ puts " lists all active contexts"
51
+ puts ""
52
+ puts "todo_rb --init"
53
+ puts " Creates todocfg.yml file in users home folder. Please edit this"
54
+ puts " file with the location of your todo.txt file"
55
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "todo_txt_rb/version"
2
+ require_relative "todo_txt_rb/todo"
3
+ require_relative "todo_txt_rb/list"
4
+ require 'yaml'
5
+
6
+
7
+ module TodoTxt
8
+ def print_todo_list list
9
+ list.list.each_with_index{|todo, index| puts "#{index + 1} #{todo}"}
10
+ end
11
+
12
+ def self.init_config
13
+ default_config = {'todo_file_location' => Dir.home.to_s + '/todo.txt'}
14
+ File.open(Dir.home.to_s + '/.todocfg.yml', "w") do |file|
15
+ file.write("# todo_file_location should be set to the location of your todo.txt\n")
16
+ file.write(default_config.to_yaml)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module TodoTxt
2
+
3
+ class List < Array
4
+ def initialize(file)
5
+ @todo_list = file
6
+ @list = File.readlines(file).map{ |x| TodoTxt::Todo.new(x)}
7
+ end
8
+
9
+ def write_file
10
+ File.open(@todo_list, 'w') do |f|
11
+ @list.each{|x| f.puts x.todo.to_s}
12
+ end
13
+ end
14
+
15
+ def list
16
+ @list.collect{|x| x.todo}
17
+ end
18
+
19
+ def list_active
20
+ @list.select{|x| x.is_active?}
21
+ end
22
+
23
+ def add_todo new_todo
24
+ File.open(@todo_list, "a"){|f| f.puts new_todo }
25
+ end
26
+
27
+ def remove_todo todo_num
28
+ @list.delete_at(todo_num - 1)
29
+ self.write_file
30
+ end
31
+
32
+ def edit_todo todo_num, new_todo
33
+ @list[todo_num - 1] = TodoTxt::Todo.new(new_todo + "\n")
34
+ self.write_file
35
+ end
36
+
37
+ def list_projects
38
+ @list.collect{|x| x.projects}.flatten.uniq{|x| x.downcase}
39
+ end
40
+
41
+ def list_contexts
42
+ @list.collect{|x| x.contexts}.flatten.uniq{|x| x.capitalize}
43
+ end
44
+
45
+ def get_projects project
46
+ self.list_active.select{|x| x.todo.include?(project)}.map{|x| x.todo}
47
+ end
48
+
49
+ def get_contexts context
50
+ self.list_active.select{|x| x.todo.include?(context)}.map{|x| x.todo}
51
+ end
52
+
53
+ def complete_todo todo_num
54
+ @list[todo_num - 1].mark_complete!
55
+ @list << @list[todo_num - 1]
56
+ @list.delete_at(todo_num - 1)
57
+ self.write_file
58
+ end
59
+
60
+ def get_todo_index todo_text
61
+ @list.index{|x| x.todo.chomp.eql?(todo_text.chomp)}
62
+ end
63
+
64
+ def order_by_priority
65
+ @list.sort{|x,y| x.priority.to_s <=> y.priority.to_s}
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ module TodoTxt
2
+
3
+ class Todo
4
+
5
+ attr_accessor :todo
6
+
7
+ def initialize(todo)
8
+ @todo = todo
9
+ end
10
+
11
+ def priority todo=@todo
12
+ priority = todo[/^\([a-zA-Z]\)/]
13
+ if priority == nil
14
+ return false
15
+ else
16
+ priority.gsub(/[()]/, "").upcase
17
+ end
18
+ end
19
+
20
+ def projects todo=@todo
21
+ todo.scan(/\+\w+/)
22
+ end
23
+
24
+ def contexts todo=@todo
25
+ todo.scan(/@\w+/)
26
+ end
27
+
28
+ def creation_date todo=@todo
29
+ @todo = todo.scan(/\d{4}-\d{2}-\d{2}/).fetch(0)
30
+ end
31
+
32
+ def remove_priority! todo=@todo
33
+ @todo = todo.sub(/^\([A-Z]\)/,"").strip
34
+ end
35
+
36
+ def change_priority! priority, todo=@todo
37
+ if todo.index(/^\([A-Z]\)/) == nil
38
+ @todo = "(#{priority}) " + todo
39
+ else
40
+ @todo = todo.sub(/^\([A-Z]\)/, "(#{priority})")
41
+ end
42
+ end
43
+
44
+ def is_complete? todo=@todo
45
+ if todo.index(/^x/) == nil
46
+ false
47
+ else
48
+ true
49
+ end
50
+ end
51
+
52
+ def is_active? todo=@todo
53
+ if todo.index(/^x/) == nil
54
+ true
55
+ else
56
+ false
57
+ end
58
+ end
59
+
60
+ def mark_complete! todo=@todo
61
+ @todo = "x #{Date.today.strftime("%F")} " + @todo
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module TodoTxtRb
2
+ VERSION = "0.0.1"
3
+ end
data/spec/list_spec.rb ADDED
@@ -0,0 +1,141 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'todo_txt_rb'
3
+ require 'fakefs/spec_helpers'
4
+
5
+ describe TodoTxt::List do
6
+ before(:each) do
7
+ include FakeFS::SpecHelpers
8
+ File.open("todo.txt", "w") do |f|
9
+ f.puts "(A) This is a test todo 1"
10
+ f.puts "(B) 2012-12-12 This test todo has a creation date"
11
+ f.puts "2011-11-11 this has a creation date no priority"
12
+ f.puts "This has a context @car @work @phone"
13
+ f.puts "This has a project +work +programming +beer"
14
+ f.puts "(C) This has both Context and project +beer @car"
15
+ f.puts "x this is a completed todo"
16
+ f.puts "x 2012-01-13 this is a completed todo with completion date +beer"
17
+ end
18
+ end
19
+
20
+ describe "#list" do
21
+ it "returns an array of all Todos" do
22
+ expected = ["(A) This is a test todo 1\n", "(B) 2012-12-12 This test todo has a creation date\n", "2011-11-11 this has a creation date no priority\n", "This has a context @car @work @phone\n", "This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n", "x this is a completed todo\n", "x 2012-01-13 this is a completed todo with completion date +beer\n"]
23
+ subject = TodoTxt::List.new "todo.txt"
24
+ subject.list.should eq expected
25
+ end
26
+ end
27
+ describe "#add_todo" do
28
+ it "adds a todo" do
29
+ subject = TodoTxt::List.new "todo.txt"
30
+ subject.add_todo("This is an additional todo")
31
+ IO.readlines("todo.txt").size.should eq 9
32
+ end
33
+ end
34
+ describe "#remove_todo" do
35
+ it "removes a todo" do
36
+ subject = TodoTxt::List.new "todo.txt"
37
+ subject.remove_todo(2)
38
+ IO.readlines("todo.txt").size.should eq 7
39
+ end
40
+
41
+ it "removes specified todo" do
42
+ expected = ["(A) This is a test todo 1\n", "2011-11-11 this has a creation date no priority\n", "This has a context @car @work @phone\n", "This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n", "x this is a completed todo\n", "x 2012-01-13 this is a completed todo with completion date +beer\n"]
43
+ subject = TodoTxt::List.new "todo.txt"
44
+ subject.remove_todo(2)
45
+ subject.list.should eq expected
46
+ end
47
+ end
48
+
49
+ describe "#edit_todo" do
50
+ it "replaces a todo" do
51
+ subject = TodoTxt::List.new "todo.txt"
52
+ subject.edit_todo(2, "This is a new edited todo")
53
+ subject.list.size.should eq 8
54
+ end
55
+
56
+ it "overwrites a todo" do
57
+ expected = ["(A) This is a test todo 1\n", "This is a new edited todo\n", "2011-11-11 this has a creation date no priority\n", "This has a context @car @work @phone\n", "This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n", "x this is a completed todo\n", "x 2012-01-13 this is a completed todo with completion date +beer\n"]
58
+ subject = TodoTxt::List.new "todo.txt"
59
+ subject.edit_todo(2, "This is a new edited todo")
60
+ subject.list.should eq expected
61
+ end
62
+ end
63
+
64
+ describe '#list_active' do
65
+ it "returns an array of active todos" do
66
+ expected = ["(A) This is a test todo 1\n", "(B) 2012-12-12 This test todo has a creation date\n", "2011-11-11 this has a creation date no priority\n", "This has a context @car @work @phone\n", "This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n"]
67
+ subject = TodoTxt::List.new "todo.txt"
68
+ subject.list_active.size.should eq 6
69
+ end
70
+ end
71
+
72
+ describe "#list_projects" do
73
+ it "returns an array of unique project tags" do
74
+ expected = ["+work", "+programming", "+beer"]
75
+ subject = TodoTxt::List.new "todo.txt"
76
+ subject.list_projects.should eq expected
77
+ end
78
+ end
79
+
80
+ describe "#list_contexts" do
81
+ it "returns an array of unique context tags" do
82
+ expected = ["@car", "@work", "@phone"]
83
+ subject = TodoTxt::List.new "todo.txt"
84
+ subject.list_contexts.should eq expected
85
+ end
86
+ end
87
+
88
+ describe "#get_projects" do
89
+ it "returns an array of all todos with project" do
90
+ expected = ["This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n"]
91
+ subject = TodoTxt::List.new "todo.txt"
92
+ subject.get_projects("+beer").should eq expected
93
+ end
94
+ end
95
+
96
+ describe "#get_contexts" do
97
+ it "returns an array of all todos with context" do
98
+ expected = ["This has a context @car @work @phone\n", "(C) This has both Context and project +beer @car\n"]
99
+ subject = TodoTxt::List.new "todo.txt"
100
+ subject.get_contexts("@car").should eq expected
101
+ end
102
+ end
103
+
104
+ describe "#complete_todo" do
105
+ it "marks a todo completed" do
106
+ expected = ["(B) 2012-12-12 This test todo has a creation date\n", "2011-11-11 this has a creation date no priority\n", "This has a context @car @work @phone\n", "This has a project +work +programming +beer\n", "(C) This has both Context and project +beer @car\n", "x this is a completed todo\n", "x 2012-01-13 this is a completed todo with completion date +beer\n", "x #{Date.today.strftime("%F")} (A) This is a test todo 1\n"]
107
+ subject = TodoTxt::List.new "todo.txt"
108
+ subject.complete_todo(1)
109
+ subject.list.should eq expected
110
+ end
111
+ end
112
+
113
+ describe '#order_by_priority' do
114
+ it "returns an array" do
115
+ subject = TodoTxt::List.new "todo.txt"
116
+ subject.order_by_priority.class.should eq Array
117
+ end
118
+
119
+ it "returns an array of todo objects" do
120
+ subject = TodoTxt::List.new "todo.txt"
121
+ subject.order_by_priority[1].class.should eq TodoTxt::Todo
122
+ end
123
+
124
+ it "orders the todo list by priority" do
125
+ expected = ["(A) This is a test todo 1\n", "(B) 2012-12-12 This test todo has a creation date\n", "(C) This has both Context and project +beer @car\n", "This has a project +work +programming +beer\n", "This has a context @car @work @phone\n", "2011-11-11 this has a creation date no priority\n", "x this is a completed todo\n", "x 2012-01-13 this is a completed todo with completion date +beer\n"]
126
+ subject = TodoTxt::List.new "todo.txt"
127
+ subject.order_by_priority.collect{|x| x.todo}.should eq expected
128
+ end
129
+
130
+
131
+ end
132
+
133
+ describe "#get_todo_index" do
134
+ it "returns the matchin todo's index" do
135
+ expected = 1
136
+ input = "(B) 2012-12-12 This test todo has a creation date"
137
+ subject = TodoTxt::List.new "todo.txt"
138
+ subject.get_todo_index(input).should eq expected
139
+ end
140
+ end
141
+ end
data/spec/todo.txt ADDED
@@ -0,0 +1,8 @@
1
+ (A) This is a test todo 1
2
+ (A) 2012-12-12 This test todo has a creation date
3
+ 2011-11-11 this has a creation date no priority
4
+ This has a context @Car @Work @Phone
5
+ This has a project +work +programming +beer
6
+ This has both Context and project +beer @car
7
+ x this is a completed todo
8
+ x 2012-01-13 this is a completed todo with completion date +beer
@@ -0,0 +1,73 @@
1
+ require 'fakefs/spec_helpers'
2
+ describe 'Todo_rb' do
3
+
4
+ before(:each) do
5
+ include FakeFS::SpecHelpers
6
+ File.open(Dir.home.to_s + "/todo.txt", "w") do |f|
7
+ f.puts "(A) This is a test todo 1"
8
+ f.puts "(B) 2012-12-12 This test todo has a creation date"
9
+ f.puts "2011-11-11 this has a creation date no priority"
10
+ f.puts "This has a context @Car @Work @Phone"
11
+ f.puts "This has a project +work +programming +beer"
12
+ f.puts "This has both Context and project +beer @car"
13
+ f.puts "x this is a completed todo"
14
+ f.puts "x 2012-01-13 this is a completed todo with completion date +beer"
15
+ end
16
+ `bin/todo_rb --init`
17
+ end
18
+
19
+ describe 'list' do
20
+
21
+ it "lists all todos" do
22
+ expected = "1 (A) This is a test todo 1\n2 (B) 2012-12-12 This test todo has a creation date\n3 2011-11-11 this has a creation date no priority\n4 This has a context @Car @Work @Phone\n5 This has a project +work +programming +beer\n6 This has both Context and project +beer @car\n7 x this is a completed todo\n8 x 2012-01-13 this is a completed todo with completion date +beer\n"
23
+ `bin/todo_rb list`.should eq expected
24
+ end
25
+
26
+ end
27
+
28
+ describe 'add' do
29
+ it "adds a todo" do
30
+ expected = "1 (A) This is a test todo 1\n2 (B) 2012-12-12 This test todo has a creation date\n3 2011-11-11 this has a creation date no priority\n4 This has a context @Car @Work @Phone\n5 This has a project +work +programming +beer\n6 This has both Context and project +beer @car\n7 x this is a completed todo\n8 x 2012-01-13 this is a completed todo with completion date +beer\n9 testing an added todo\n"
31
+ `bin/todo_rb add testing an added todo`
32
+ `bin/todo_rb list`.should eq expected
33
+ end
34
+ end
35
+
36
+ describe 'rm' do
37
+ it "deletes a todo" do
38
+ expected = "1 (B) 2012-12-12 This test todo has a creation date\n2 2011-11-11 this has a creation date no priority\n3 This has a context @Car @Work @Phone\n4 This has a project +work +programming +beer\n5 This has both Context and project +beer @car\n6 x this is a completed todo\n7 x 2012-01-13 this is a completed todo with completion date +beer\n"
39
+ `bin/todo_rb rm 1`
40
+ `bin/todo_rb list`.should eq expected
41
+ end
42
+ end
43
+
44
+ describe 'do' do
45
+ it "marks a todo complete" do
46
+ expected = "1 (B) 2012-12-12 This test todo has a creation date\n2 2011-11-11 this has a creation date no priority\n3 This has a context @Car @Work @Phone\n4 This has a project +work +programming +beer\n5 This has both Context and project +beer @car\n6 x this is a completed todo\n7 x 2012-01-13 this is a completed todo with completion date +beer\n8 x #{Date.today.strftime("%F")} (A) This is a test todo 1\n"
47
+ `bin/todo_rb do 1`
48
+ `bin/todo_rb list`.should eq expected
49
+ end
50
+ end
51
+
52
+ describe 'replace' do
53
+ it "replaces a todo" do
54
+ expected = "1 Replacement Todo\n2 (B) 2012-12-12 This test todo has a creation date\n3 2011-11-11 this has a creation date no priority\n4 This has a context @Car @Work @Phone\n5 This has a project +work +programming +beer\n6 This has both Context and project +beer @car\n7 x this is a completed todo\n8 x 2012-01-13 this is a completed todo with completion date +beer\n"
55
+ `bin/todo_rb replace 1 Replacement Todo`
56
+ `bin/todo_rb list`.should eq expected
57
+ end
58
+ end
59
+
60
+ describe 'listproj' do
61
+ it "lists all projects" do
62
+ expected = "+work, +programming, +beer\n"
63
+ `bin/todo_rb listproj`.should eq expected
64
+ end
65
+ end
66
+
67
+ describe 'listcontext' do
68
+ it "lists all contexts" do
69
+ expected = "@Car, @Work, @Phone\n"
70
+ `bin/todo_rb listcontext`.should eq expected
71
+ end
72
+ end
73
+ end
data/spec/todo_spec.rb ADDED
@@ -0,0 +1,139 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'todo_txt_rb'
3
+
4
+ describe TodoTxt::Todo do
5
+ describe '#priority' do
6
+ it "returns the priority" do
7
+ input = "(A) this is a test todo"
8
+ expected = "A"
9
+ subject = TodoTxt::Todo.new input
10
+ subject.priority(input).should eq expected
11
+ end
12
+
13
+ it "returns an upper case priority" do
14
+ input = "(a) this is a test todo"
15
+ expected = "A"
16
+ subject = TodoTxt::Todo.new input
17
+ subject.priority(input).should eq expected
18
+ end
19
+
20
+ it "returns the first priority" do
21
+ input = "(A) this is a test todo (b) (B)"
22
+ expected = "A"
23
+ subject = TodoTxt::Todo.new input
24
+ subject.priority.should eq expected
25
+ end
26
+
27
+ it "returns false if there is no priority" do
28
+ input = "there is no priority"
29
+ expected = false
30
+ subject = TodoTxt::Todo.new input
31
+ subject.priority.should eq expected
32
+ end
33
+ end
34
+
35
+ describe '#projects' do
36
+ it "returns an array of projects" do
37
+ input = "(A) this is a test todo +stuff +things +project"
38
+ expected = ["+stuff", "+things", "+project"]
39
+ subject = TodoTxt::Todo.new input
40
+ subject.projects.should eq expected
41
+ end
42
+ end
43
+
44
+ describe '#contexts' do
45
+ it "returns an array of contexts" do
46
+ input = "(A) this is a test todo @Concur @Work"
47
+ expected = ["@Concur", "@Work"]
48
+ subject = TodoTxt::Todo.new input
49
+ subject.contexts.should eq expected
50
+ end
51
+ end
52
+
53
+ describe '#creation_date' do
54
+ it "returns a date" do
55
+ input = "(A) 2013-01-01 This is a test todo"
56
+ expected = "2013-01-01"
57
+ subject = TodoTxt::Todo.new input
58
+ subject.creation_date.should eq expected
59
+ end
60
+
61
+ it "returns the date right after the priority" do
62
+ input = "(A) 2013-01-01 2012-01-01 yaya todo 2010-01-01"
63
+ expected = "2013-01-01"
64
+ subject = TodoTxt::Todo.new input
65
+ subject.creation_date.should eq expected
66
+ end
67
+ end
68
+
69
+ describe '#remove_priority!' do
70
+ it "removes the priority if there is one present" do
71
+ input = "(A) this is a todo with a priority"
72
+ expected = "this is a todo with a priority"
73
+ subject = TodoTxt::Todo.new input
74
+ subject.remove_priority!.should eq expected
75
+ end
76
+ end
77
+
78
+ describe '#change_priority!' do
79
+ it "adds a priority if one does not exist" do
80
+ input = "this todo has no priority."
81
+ expected = "(A) this todo has no priority."
82
+ subject = TodoTxt::Todo.new input
83
+ subject.change_priority!("A").should eq expected
84
+ end
85
+
86
+ it "changes the priority if one exists" do
87
+ input = "(A) this todo has a priority"
88
+ expected = "(C) this todo has a priority"
89
+ subject = TodoTxt::Todo.new input
90
+ subject.change_priority!('C').should eq expected
91
+ end
92
+ end
93
+
94
+ describe '#is_complete?' do
95
+ it "returns true if todo starts with 'x'" do
96
+ input = "x (A) this is a completed todo"
97
+ subject = TodoTxt::Todo.new input
98
+ subject.is_complete?.should eq true
99
+ end
100
+
101
+ it "returns false if todo does not start with 'x'" do
102
+ input = "(A) this is not a completed todo"
103
+ subject = TodoTxt::Todo.new input
104
+ subject.is_complete?.should eq false
105
+ end
106
+ end
107
+
108
+ describe '#is_active?' do
109
+ it "returns true if the todo is not complete" do
110
+ input = "(A) this is not a complete todo"
111
+ subject = TodoTxt::Todo.new input
112
+ subject.is_active?.should eq true
113
+ end
114
+
115
+ it "returns false if the todo is complete" do
116
+ input = "x (A) this is a complete todo"
117
+ subject = TodoTxt::Todo.new input
118
+ subject.is_active?.should eq false
119
+ end
120
+ end
121
+
122
+ describe '#mark_complete' do
123
+ it "adds a 'x' to the beginning of a todo" do
124
+ expected = "x #{Date.today.strftime("%F")} (A) this is a todo"
125
+ input = "(A) this is a todo"
126
+ subject = TodoTxt::Todo.new input
127
+ subject.mark_complete!.should eq expected
128
+ end
129
+
130
+ it "adds the completed date to the todo" do
131
+ expected = "x #{Date.today.strftime("%F")} (A) this is a todo"
132
+ input = "(A) this is a todo"
133
+ subject = TodoTxt::Todo.new input
134
+ subject.mark_complete!.should eq expected
135
+ end
136
+ end
137
+
138
+
139
+ end
data/todo.txt ADDED
@@ -0,0 +1,8 @@
1
+ (A) This is a test todo 1
2
+ (B) 2012-12-12 This test todo has a creation date
3
+ 2011-11-11 this has a creation date no priority
4
+ This has a context @car @work @phone
5
+ This has a project +work +programming +beer
6
+ (C) This has both Context and project +beer @car
7
+ x this is a completed todo
8
+ x 2012-01-13 this is a completed todo with completion date +beer
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'todo_txt_rb/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "todo_txt_rb"
8
+ gem.version = TodoTxtRb::VERSION
9
+ gem.authors = ["Chris Lee"]
10
+ gem.email = ["finges@gmail.com"]
11
+ gem.description = "Ruby Implementation of the Todo.txt CLI"
12
+ gem.summary = "Ruby Implementation of the Todo.txt CLI"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todo_txt_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Ruby Implementation of the Todo.txt CLI
15
+ email:
16
+ - finges@gmail.com
17
+ executables:
18
+ - todo_rb
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - .rspec
24
+ - Gemfile
25
+ - Guardfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/todo_rb
30
+ - lib/todo_txt_rb.rb
31
+ - lib/todo_txt_rb/list.rb
32
+ - lib/todo_txt_rb/todo.rb
33
+ - lib/todo_txt_rb/version.rb
34
+ - spec/list_spec.rb
35
+ - spec/todo.txt
36
+ - spec/todo_rb_spec.rb
37
+ - spec/todo_spec.rb
38
+ - todo.txt
39
+ - todo_txt_rb.gemspec
40
+ homepage: ''
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.24
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Ruby Implementation of the Todo.txt CLI
64
+ test_files:
65
+ - spec/list_spec.rb
66
+ - spec/todo.txt
67
+ - spec/todo_rb_spec.rb
68
+ - spec/todo_spec.rb
69
+ has_rdoc: