to-do 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,9 +6,8 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  gem "shoulda", ">= 0"
9
- gem "rdoc", "~> 3.12"
10
-
11
- gem "bundler", "~> 1.0.0"
9
+ gem "sqlite3", ">=0"
10
+ gem "bundler", ">= 1.0.0"
12
11
  gem "jeweler", "~> 1.8.4"
13
12
  gem "simplecov", ">= 0"
14
13
  gem "colorize", ">= 0"
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- #to-do 1.2.1
1
+ #to-do 1.2.2
2
2
 
3
- A simple command line todo application.
3
+ A simple command line todo application written in Ruby.
4
4
 
5
- ##What's new 1.2.1
5
+ ##What's new 1.2.2
6
+ * Switch from yaml to sqlite for data persistence
6
7
  * Bug Fixes
7
8
 
8
9
  ##What's new in 1.2
@@ -16,13 +17,13 @@ A simple command line todo application.
16
17
  ##Features
17
18
  * Basic todo list functionality
18
19
  * Add items
19
- * Delete items
20
+ * Complete items
21
+ * Clear list
22
+ * Display list
20
23
  * Multiple lists
21
- * Clear list
22
- * Display list
23
24
  * Colored display
24
- * Undo completing
25
- * Removelists
25
+ * Undo Completing
26
+ * Remove lists
26
27
 
27
28
  ##How to Use
28
29
 
@@ -73,7 +74,7 @@ A simple command line todo application.
73
74
  todo undo write paper
74
75
  todo u -n 2
75
76
 
76
- ###Clear completed tasks
77
+ ###Clear completed tasks and reset completed count
77
78
 
78
79
  todo clear
79
80
 
@@ -99,7 +100,7 @@ A simple command line todo application.
99
100
  * Tags
100
101
  * Due Dates
101
102
  * Tab Completion
102
- * YAML Record
103
+ * SQLite Backend
103
104
  * Sorting
104
105
  * Priorites
105
106
  * Reorganizing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
data/lib/to-do.rb CHANGED
@@ -1,14 +1,46 @@
1
- require 'rdoc'
1
+ require 'sqlite3'
2
2
  require File.join(File.dirname(__FILE__), 'to-do', 'config')
3
- require File.join(File.dirname(__FILE__), 'to-do', 'list')
4
3
  if !File.exists?(File.join(ENV['HOME'], '.to-do'))
5
4
  Dir.mkdir(File.join(ENV['HOME'], '.to-do'))
6
5
  Todo::Config.write
7
- Dir.mkdir(Todo::Config[:lists_directory])
8
- #Todo::List.new "Default List"
9
6
  end
7
+
8
+ # If the Database doesn't exist, create it
9
+ if !File.exists?(Todo::Config[:task_database])
10
+ Todo::Config.write
11
+ database = SQLite3::Database.new(Todo::Config[:task_database])
12
+ database.execute "CREATE TABLE Tasks(Id INTEGER PRIMARY KEY, Task_number INTEGER, Name TEXT, Completed INTEGER)"
13
+ database.execute "CREATE TABLE Lists(Id INTEGER PRIMARY KEY, Name TEXT, Total INTEGER)"
14
+ database.execute "CREATE TABLE Task_list(Task_id INTEGER, List_id INTEGER)"
15
+
16
+ # If you have existing lists from earlier versions stored in YAML, stick them
17
+ # in the sqlite database
18
+ if File.exists?(File.join(ENV['HOME'], '.to-do', 'lists'))
19
+ Dir.chdir(File.join(ENV['HOME'], '.to-do', 'lists')) do
20
+ lists = Dir.entries "."
21
+ lists.each do |file|
22
+ next if file == "." or file == ".."
23
+ list_object = YAML.load_file(file)
24
+ database.execute "INSERT INTO Lists (Name, Total) VALUES('" + list_object.name + "', " + list_object.count.to_s + ")"
25
+ list_id = database.last_insert_row_id
26
+ list_object.tasks.each do |num, task|
27
+ database.execute "INSERT INTO Tasks (Task_number, Name, Completed) VALUES('" + num.to_s + "', '" + task + "', 0)"
28
+ task_id = database.last_insert_row_id
29
+ database.execute "INSERT INTO Task_list VALUES(" + task_id.to_s + ", " + list_id.to_s + ")"
30
+ end
31
+ list_object.completed_tasks.each do |num, task|
32
+ database.execute "INSERT INTO Tasks (Task_number, Name, Completed) VALUES('" + num.to_s + "', '" + task + "', 1)"
33
+ task_id = database.last_insert_row_id
34
+ database.execute "INSERT INTO Task_list VALUES(" + task_id.to_s + ", " + list_id.to_s + ")"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ require File.join(File.dirname(__FILE__), 'to-do', 'tasks')
10
41
  require File.join(File.dirname(__FILE__), 'to-do', 'cli')
11
42
 
43
+
12
44
  # Todo is the main namespace that all of the other modules and classes are a
13
45
  # part of
14
46
  module Todo
data/lib/to-do/cli.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require 'optparse'
2
2
  require 'yaml'
3
3
  require 'colorize'
4
+ require 'sqlite3'
4
5
 
5
6
  module Todo
6
7
  # CLI is the module that contains the methods to display the list as well as
7
8
  # the methods to parse command line arguments.
8
9
  module CLI
9
10
  extend self
10
- # The current working list
11
- WORKING_LIST=YAML.load_file(File.join(Config[:lists_directory], Config[:working_list_name]+'.yml')) if File.exists?(File.join(Config[:lists_directory], Config[:working_list_name]+'.yml'))
11
+
12
+ # The database
13
+ DATABASE = SQLite3::Database.new(Todo::Config[:task_database])
12
14
 
13
15
  # The option flags
14
16
  OPTIONS = {
@@ -32,21 +34,33 @@ module Todo
32
34
  # 4. Task 4
33
35
  #
34
36
  # @param [List] list the list you want to display.
35
- def display list = WORKING_LIST
37
+ def display list = []
38
+ tasks = DATABASE.execute "SELECT Task_number, Name, Completed FROM Tasks WHERE Id IN
39
+ (SELECT Task_id FROM Task_list WHERE List_id IN
40
+ (SELECT Id FROM Lists Where Lists.Name='" + Config[:working_list_name]+"'))"
41
+ tasks.sort!{|x, y| x[0] <=> y[0]}
42
+ list = DATABASE.execute("SELECT Total FROM Lists WHERE Name = '" + Config[:working_list_name] + "'")
43
+ count = list ? list[0][0] : 0
44
+ completed_count = 0
36
45
  puts "********************************".colorize(:light_red)
37
- puts list.name.center(32).colorize(:light_cyan)
46
+ puts Config[:working_list_name].center(32).colorize(:light_cyan)
38
47
  puts "********************************".colorize(:light_red)
39
48
  puts
40
49
  puts "Todo:".colorize(:light_green)
41
- list.tasks.each do |k,v|
42
- printf "%4d. ".to_s.colorize(:light_yellow), k
43
- puts v
50
+ tasks.each do |task|
51
+ if task[2] == 1
52
+ completed_count +=1
53
+ next
54
+ end
55
+ printf "%4d. ".to_s.colorize(:light_yellow), task[0]
56
+ puts task[1]
44
57
  end
45
58
  print "\nCompleted:".colorize(:light_green)
46
- printf "%36s\n", "#{list.completed_count}/#{list.count}".colorize(:light_cyan)
47
- list.completed_tasks.each do |k,v|
48
- printf "%4d. ".to_s.colorize(:light_yellow), k
49
- puts v
59
+ printf "%36s\n", "#{completed_count}/#{count}".colorize(:light_cyan)
60
+ tasks.each do |task|
61
+ next if task[2] == 0
62
+ printf "%4d. ".to_s.colorize(:light_yellow), task[0]
63
+ puts task[1]
50
64
  end
51
65
  puts
52
66
  end
@@ -58,12 +72,12 @@ module Todo
58
72
  opts.version = File.exist?(version_path) ? File.read(version_path) : ""
59
73
  opts.banner = "Usage: todo [COMMAND] [option] [arguments]"
60
74
  opts.separator "Commands:"
75
+ opts.separator " create, switch <list name> creates a new list or switches to an existing one"
61
76
  opts.separator " <blank>, display, d displays the current list"
62
77
  opts.separator " add, a <task> adds the task to the current list"
63
78
  opts.separator " finish, f [option] <task> marks the task as completed"
64
- opts.separator " clear [option] clears completed tasks"
65
79
  opts.separator " undo, u [option] <task> undos a completed task"
66
- opts.separator " create, switch <list name> creates a new list or switches to an existing one"
80
+ opts.separator " clear [option] clears completed tasks"
67
81
  opts.separator " remove, rm <list name> removes the list completely (cannot undo)"
68
82
  opts.separator "Options: "
69
83
  opts.on('-n', 'with finish or undo, references a task by its number') do
@@ -78,7 +92,7 @@ module Todo
78
92
  end
79
93
  opts.on('-w', "displays the name of the current list") do
80
94
  if Config[:working_list_exists]
81
- puts "Working list is #{WORKING_LIST.name}"
95
+ puts "Working list is #{Config[:working_list_name]}"
82
96
  else
83
97
  puts "Working List does not exist yet. Please create one"
84
98
  puts "todo create <list name>"
@@ -92,63 +106,63 @@ module Todo
92
106
  def commands_parser
93
107
  if ARGV.count > 0
94
108
  case ARGV[0]
95
- when "add", "a"
109
+ when "display", "d"
96
110
  if Config[:working_list_exists]
97
- ARGV.count > 1 ? WORKING_LIST.add(ARGV[1..-1].join(' ')) : puts("Usage: todo add <task name>")
98
111
  display
99
112
  else
100
113
  puts "Working List does not exist yet. Please create one"
101
114
  puts "todo create <list name>"
102
115
  end
103
- when "finish", "f"
116
+ when "create", "switch"
117
+ if ARGV.count > 0
118
+ name = ARGV[1..-1].map{|word| word.capitalize}.join(' ')
119
+ Config[:working_list_name] = name
120
+ Config[:working_list_exists] = true
121
+ puts "Switch to #{name}"
122
+ puts
123
+ display
124
+ else
125
+ puts "Usage: todo #{ARGV[0]} <listname>"
126
+ end
127
+ when "add", "a"
104
128
  if Config[:working_list_exists]
105
- WORKING_LIST.finish ARGV[1..-1].join(' '), OPTIONS[:is_num]
129
+ ARGV.count > 1 ? Tasks.add(ARGV[1..-1].join(' ')) : puts("Usage: todo add <task name>")
130
+ puts
106
131
  display
107
132
  else
108
133
  puts "Working List does not exist yet. Please create one"
109
134
  puts "todo create <list name>"
110
135
  end
111
- when "clear"
136
+ when "finish", "f"
112
137
  if Config[:working_list_exists]
113
- WORKING_LIST.clear OPTIONS[:clear_all]
138
+ ARGV.count > 1 ? Tasks.finish(ARGV[1..-1].join(' '), OPTIONS[:is_num]) : puts("Usage: todo finish <task name>")
139
+ puts
140
+ display
114
141
  else
115
142
  puts "Working List does not exist yet. Please create one"
116
143
  puts "todo create <list name>"
117
144
  end
118
- when "display", "d"
145
+ when "undo", "u"
119
146
  if Config[:working_list_exists]
147
+ ARGV.count > 1 ? Tasks.undo(ARGV[1..-1].join(' '), OPTIONS[:is_num]) : puts("Usage: todo undo <task name>")
148
+ puts
120
149
  display
121
150
  else
122
151
  puts "Working List does not exist yet. Please create one"
123
152
  puts "todo create <list name>"
124
153
  end
125
- when "create", "switch"
126
- if File.exists?(File.join(Config[:lists_directory], ARGV[1..-1].join('_').downcase + '.yml'))
127
- Config[:working_list_name] = ARGV[1..-1].join('_').downcase
128
- Config[:working_list_exists] = true
129
- puts "Switch to #{ARGV[1..-1].join(' ')}"
130
- new_list = YAML.load_file(File.join(Config[:lists_directory],
131
- Config[:working_list_name]+'.yml')) if File.exists?(File.join(Config[:lists_directory],
132
- Config[:working_list_name]+'.yml'))
133
- display new_list
134
- else
135
- ARGV.count > 1 ? List.new(ARGV[1..-1].join(' ')) : puts("Usage: todo create <list_name> ")
136
- new_list = YAML.load_file(File.join(Config[:lists_directory],
137
- Config[:working_list_name]+'.yml')) if File.exists?(File.join(Config[:lists_directory],
138
- Config[:working_list_name]+'.yml'))
139
- display new_list
140
- end
141
- when "undo", "u"
154
+ when "clear"
142
155
  if Config[:working_list_exists]
143
- WORKING_LIST.undo ARGV[1..-1].join(' '), OPTIONS[:is_num]
144
- display
156
+ Tasks.clear OPTIONS[:clear_all]
157
+ puts
158
+ display
145
159
  else
146
160
  puts "Working List does not exist yet. Please create one"
147
161
  puts "todo create <list name>"
148
- end
162
+ end
149
163
  when "remove", "r"
150
164
  if ARGV.count > 1
151
- List.remove ARGV[1..-1].join(' ')
165
+ Tasks.clear true, ARGV[1..-1].map{|word| word.capitalize}.join(' ')
152
166
  end
153
167
  else
154
168
  puts "Invalid command. See todo -h for help."
@@ -174,5 +188,40 @@ module Todo
174
188
  end
175
189
  end
176
190
 
191
+ # splits string for wrapping
192
+ def split string, width
193
+ split = Array.new
194
+ if string.length > width #if the string needs to be split
195
+ string_words = string.split(" ")
196
+ line = ""
197
+ string_words.each do |x|
198
+ if x.length > width #if the word needs to be split
199
+ #add the start of the word onto the first line (even if it has already started)
200
+ while line.length < width
201
+ line += x[0]
202
+ x = x[1..-1]
203
+ end
204
+ split << line
205
+ #split the rest of the word up onto new lines
206
+ split_word = x.scan(%r[.{1,#{width}}])
207
+ split_word[0..-2].each do |word|
208
+ split << word
209
+ end
210
+ line = split_word.last+" "
211
+ elsif (line + x).length > width-1 #if the word would fit alone on its own line
212
+ split << line.chomp
213
+ line = x
214
+ else #if the word can be added to this line
215
+ line += x + " "
216
+ end
217
+ end
218
+ split << line
219
+ else #if the string doesn't need to be split
220
+ split = [string]
221
+ end
222
+ #give back the split line
223
+ return split
224
+ end
225
+
177
226
  end
178
227
  end
data/lib/to-do/config.rb CHANGED
@@ -18,10 +18,14 @@ module Todo
18
18
  {
19
19
  # the location of all all your list yaml files
20
20
  :lists_directory => File.join(ENV["HOME"],".to-do","lists"),
21
+ # a sqlite3 databse that contains all of the tasks
22
+ :task_database => File.join(ENV["HOME"], ".to-do", "to-do.sqlite"),
21
23
  # the current working list
22
24
  :working_list_name => "default_list",
23
25
  # does the working list actually exist
24
- :working_list_exists => false
26
+ :working_list_exists => false,
27
+ # default width for formatting
28
+ :width => 50
25
29
  }
26
30
  end
27
31
 
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), 'config')
2
+ require 'fileutils'
3
+ require 'sqlite3'
4
+ module Todo
5
+
6
+ # The module that contains methods for manipulating the database
7
+ module Tasks
8
+ extend self
9
+ DATABASE = SQLite3::Database.new(Todo::Config[:task_database])
10
+
11
+ # Adds the tast to the list
12
+ #
13
+ # @param [String] task the task to add to the list
14
+ def add task
15
+ list = DATABASE.execute("SELECT Total, Id FROM Lists WHERE Name = '" + Config[:working_list_name] + "'")
16
+ if !list
17
+ Database.execute("INSERT INTO Lists (Name, Total) VALUES('" + Config[:working_list_name] + "', 0)")
18
+ end
19
+ count = list ? list[0][0]+1 : 1
20
+ DATABASE.execute "INSERT INTO Tasks (Task_number, Name, Completed) VALUES('" + count.to_s + "', '" + task + "', 0)"
21
+ list_id = list[0][1]
22
+ task_id = DATABASE.last_insert_row_id
23
+ DATABASE.execute "INSERT INTO Task_list VALUES(" + task_id.to_s + ", " + list_id.to_s + ")"
24
+ DATABASE.execute "UPDATE Lists SET Total="+ count.to_s + " WHERE Id = " + list_id.to_s
25
+ end
26
+
27
+ # finish the task. task is either a case insensitive task on the list or
28
+ # the task number. Prints out either the task is not in the list or that i
29
+ # succesfully finished the task
30
+ #
31
+ # @param task either a task number or task name to finish
32
+ # @param [Bool] is_num if the task param represents the task number, true.
33
+ # false if it is the task name
34
+ def finish task, is_num
35
+ finish_undo task, is_num, 0, 1
36
+ end
37
+
38
+ # undos finishing a task. task is either a case insensitive task on the list or
39
+ # the task number. Prints out either the task is not in the list or that i
40
+ # succesfully undoed finished the task
41
+ #
42
+ # @param task either a task number or task name to finish
43
+ # @param [Bool] is_num if the task param represents the task number, true.
44
+ # false if it is the task name
45
+ def undo task, is_num
46
+ finish_undo task, is_num, 1, 0
47
+ end
48
+
49
+ # clears either just the completed or the uncompleted tasks
50
+ #
51
+ # @param completed [Integer] 1 if clearing completed tasks, 0 if clearing
52
+ # Uncompleted tasks
53
+ def clear_each completed ,list_name
54
+ tasks = DATABASE.execute("SELECT Id from Tasks WHERE Id IN
55
+ (SELECT Task_ID FROM Task_list WHERE List_Id IN
56
+ (SELECT Id FROM Lists WHERE Name='"+list_name+"' AND Tasks.Completed ="+ completed.to_s+ "))")
57
+ tasks.each do |task|
58
+ DATABASE.execute("DELETE FROM Task_list WHERE Task_id=" + task[0].to_s)
59
+ DATABASE.execute("DELETE FROM Tasks WHERE Id=" + task[0].to_s)
60
+ end
61
+ end
62
+
63
+ # clears all the tasks in the list
64
+ #
65
+ # @param [Bool] clear_all if true, clears all completed and uncompleted tasks
66
+ # and resets the count. if false, just clears the completed tasks
67
+ def clear clear_all, list_name = Config[:working_list_name]
68
+ clear_each 1, list_name
69
+ if clear_all
70
+ clear_each 0, list_name
71
+ DATABASE.execute("UPDATE Lists SET Total = 0 WHERE Name = '" + list_name +"'")
72
+ DATABASE.execute("DELETE FROM Lists WHERE Name = '" + list_name + "'")
73
+ puts "Cleared all tasks in #{list_name}"
74
+ else
75
+ puts "Cleared completed tasks in #{Config[:working_list_name]}"
76
+ end
77
+ end
78
+
79
+ # Helper method for finishing and undoing a task
80
+ #
81
+ # @param task either a task number or task name to finish
82
+ # @param [Bool] is_num if the task param represents the task number, true.
83
+ # false if it is the task name
84
+ # @param initial [Integer] 0 if you are finishing a task, 1 if you are undoing a task
85
+ # @param final [Integer] 1 if you are finishing a task, 0 if you ara undoing a task
86
+ def finish_undo task , is_num, initial, final
87
+ list = DATABASE.execute("SELECT Id FROM Lists WHERE Name = '" + Config[:working_list_name] + "'")
88
+ list_id = list[0][0]
89
+ names = DATABASE.execute("SELECT * from Tasks WHERE Id IN
90
+ (SELECT Task_ID FROM Task_list WHERE List_Id IN
91
+ (SELECT Id FROM Lists WHERE Name='"+Config[:working_list_name]+"' AND Tasks.Completed ="+ initial.to_s+"))")
92
+ if is_num
93
+ if names.map{|t| t[1]}.include? task.to_i
94
+ task_array = names.find{|t| t[1] == task.to_i}
95
+ DATABASE.execute "Update Tasks SET Completed="+final.to_s+ " WHERE Id=" + task_array[0].to_s
96
+ else
97
+ puts "Task ##{task} is not in the list."
98
+ end
99
+ else
100
+ if names.map{|t| t[2].downcase}.include? task.downcase
101
+ task_array = names.find{|t| t[2].downcase == task.downcase}
102
+ DATABASE.execute "Update Tasks SET Completed="+final.to_s+ " WHERE Id=" + task_array[0].to_s
103
+ else
104
+ puts "Task #{task} is not in the list."
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
data/to-do.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "to-do"
8
- s.version = "1.2.1"
8
+ s.version = "1.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristen Mills"]
12
- s.date = "2012-07-15"
12
+ s.date = "2012-07-18"
13
13
  s.description = "A simple command line todo application"
14
14
  s.email = "kristen@kristen-mills.com"
15
15
  s.executables = ["todo"]
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  "lib/to-do.rb",
29
29
  "lib/to-do/cli.rb",
30
30
  "lib/to-do/config.rb",
31
- "lib/to-do/list.rb",
31
+ "lib/to-do/tasks.rb",
32
32
  "test/helper.rb",
33
33
  "test/test_to-do.rb",
34
34
  "to-do.gemspec"
@@ -44,16 +44,16 @@ Gem::Specification.new do |s|
44
44
 
45
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  s.add_runtime_dependency(%q<shoulda>, [">= 0"])
47
- s.add_runtime_dependency(%q<rdoc>, ["~> 3.12"])
48
- s.add_runtime_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
48
+ s.add_runtime_dependency(%q<bundler>, [">= 1.0.0"])
49
49
  s.add_runtime_dependency(%q<jeweler>, ["~> 1.8.4"])
50
50
  s.add_runtime_dependency(%q<simplecov>, [">= 0"])
51
51
  s.add_runtime_dependency(%q<colorize>, [">= 0"])
52
52
  s.add_development_dependency(%q<yard>, [">= 0"])
53
53
  else
54
54
  s.add_dependency(%q<shoulda>, [">= 0"])
55
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<sqlite3>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
57
57
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
58
58
  s.add_dependency(%q<simplecov>, [">= 0"])
59
59
  s.add_dependency(%q<colorize>, [">= 0"])
@@ -61,8 +61,8 @@ Gem::Specification.new do |s|
61
61
  end
62
62
  else
63
63
  s.add_dependency(%q<shoulda>, [">= 0"])
64
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<sqlite3>, [">= 0"])
65
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
66
66
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
67
67
  s.add_dependency(%q<simplecov>, [">= 0"])
68
68
  s.add_dependency(%q<colorize>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to-do
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
16
- requirement: &70161145118480 !ruby/object:Gem::Requirement
16
+ requirement: &70322464748740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,32 +21,32 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70161145118480
24
+ version_requirements: *70322464748740
25
25
  - !ruby/object:Gem::Dependency
26
- name: rdoc
27
- requirement: &70161145118000 !ruby/object:Gem::Requirement
26
+ name: sqlite3
27
+ requirement: &70322464747940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ~>
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: '3.12'
32
+ version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70161145118000
35
+ version_requirements: *70322464747940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70161145117520 !ruby/object:Gem::Requirement
38
+ requirement: &70322464747040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70161145117520
46
+ version_requirements: *70322464747040
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70161145117040 !ruby/object:Gem::Requirement
49
+ requirement: &70322464744360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.8.4
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70161145117040
57
+ version_requirements: *70322464744360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &70161145116500 !ruby/object:Gem::Requirement
60
+ requirement: &70322464758220 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70161145116500
68
+ version_requirements: *70322464758220
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: colorize
71
- requirement: &70161145115960 !ruby/object:Gem::Requirement
71
+ requirement: &70322464755580 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70161145115960
79
+ version_requirements: *70322464755580
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &70161145115400 !ruby/object:Gem::Requirement
82
+ requirement: &70322464753260 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70161145115400
90
+ version_requirements: *70322464753260
91
91
  description: A simple command line todo application
92
92
  email: kristen@kristen-mills.com
93
93
  executables:
@@ -107,7 +107,7 @@ files:
107
107
  - lib/to-do.rb
108
108
  - lib/to-do/cli.rb
109
109
  - lib/to-do/config.rb
110
- - lib/to-do/list.rb
110
+ - lib/to-do/tasks.rb
111
111
  - test/helper.rb
112
112
  - test/test_to-do.rb
113
113
  - to-do.gemspec
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 1554472922961583254
129
+ hash: -1294389487870074632
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements:
data/lib/to-do/list.rb DELETED
@@ -1,161 +0,0 @@
1
- require 'yaml'
2
- require File.join(File.dirname(__FILE__), 'config')
3
- require 'fileutils'
4
- module Todo
5
-
6
- # The Class that represents a list of tasks
7
- class List
8
- attr_accessor :tasks, :completed_tasks, :count, :completed_count, :name
9
-
10
- # Creates a new list and sets it to be the working list
11
- #
12
- # @param [String] name the name of the list
13
- def initialize name
14
- @tasks = Hash.new
15
- @completed_tasks = Hash.new
16
- @count = 0
17
- @completed_count = 0
18
- @name = name
19
- if !File.exists? Config[:lists_directory]
20
- Dir.mkdir(Config[:lists_directory])
21
- end
22
- update
23
- Config[:working_list_name] = name.downcase.gsub(/ /, '_')
24
- Config[:working_list_exists] = true
25
- Config.write
26
- puts "Created List #{name}."
27
- end
28
-
29
- # Updates the yaml file
30
- def update
31
- path = File.join(Config[:lists_directory], @name.downcase.gsub(/ /, '_') +'.yml')
32
- File.open(path, 'w') do |fh|
33
- fh.puts(self.to_yaml)
34
- end
35
- end
36
-
37
- # Adds the tast to the list
38
- #
39
- # @param [String] task the task to add to the list
40
- def add task
41
- @count+=1
42
- @tasks[@count] = task
43
- puts "Added task #{task}."
44
- update
45
- end
46
-
47
- # finish the task. task is either a case insensitive task on the list or
48
- # the task number. Prints out either the task is not in the list or that i
49
- # succesfully finished the task
50
- #
51
- # @param task either a task number or task name to finish
52
- # @param [Bool] is_num if the task param represents the task number, true.
53
- # false if it is the task name
54
- def finish task, is_num
55
- if is_num
56
- if !@tasks[task.to_i].nil?
57
- @completed_tasks[task.to_i] = @tasks[task.to_i]
58
- @tasks.delete(task.to_i)
59
- @completed_count+=1
60
- @completed_tasks = Hash[@completed_tasks.sort]
61
- puts "Finished #{@completed_tasks[task.to_i]}."
62
- else
63
- puts "Task \##{task} not in list."
64
- end
65
- else
66
- hash = Hash.new
67
- @tasks.each do |k,v|
68
- hash[k] = v.downcase
69
- end
70
- if hash.value?(task.downcase)
71
- num = hash.key(task.downcase)
72
- @completed_tasks[num] = @tasks[num]
73
- @tasks.delete(num)
74
- @completed_count+=1
75
- @completed_tasks = Hash[@completed_tasks.sort]
76
- puts "Finished #{@completed_tasks[num]}."
77
- else
78
- puts "Task #{task} is not in list."
79
- end
80
- end
81
- update
82
- end
83
-
84
- # undos finishing a task. task is either a case insensitive task on the list or
85
- # the task number. Prints out either the task is not in the list or that i
86
- # succesfully undoed finished the task
87
- #
88
- # @param task either a task number or task name to finish
89
- # @param [Bool] is_num if the task param represents the task number, true.
90
- # false if it is the task name
91
- def undo task, is_num
92
- if is_num
93
- if !@completed_tasks[task.to_i].nil?
94
- @tasks[task.to_i] = @completed_tasks[task.to_i]
95
- @completed_tasks.delete(task.to_i)
96
- @completed_count-=1
97
- @tasks = Hash[@tasks.sort]
98
- puts "Undo completeing #{@tasks[task.to_i]}."
99
- else
100
- puts "Task \##{task} not in list."
101
- end
102
- else
103
- hash = Hash.new
104
- @completed_tasks.each do |k,v|
105
- hash[k] = v.downcase
106
- end
107
- if hash.value?(task.downcase)
108
- num = hash.key(task.downcase)
109
- @tasks[num] = @completed_tasks[num]
110
- @completed_tasks.delete(num)
111
- @completed_count-=1
112
- @tasks = Hash[@tasks.sort]
113
- puts "Undo completeing #{@tasks[num]}."
114
- else
115
- puts "Task #{task} is not in list."
116
- end
117
- end
118
- update
119
- end
120
-
121
- # clears just the completed tasks
122
- def clear_completed
123
- @completed_tasks = Hash.new
124
- update
125
- end
126
-
127
- # clears the task in the list
128
- #
129
- # @param [Bool] clear_all if true, clears all completed and uncompleted tasks
130
- # and resets the count. if false, just clears the completed tasks
131
- def clear clear_all
132
- clear_completed
133
- if clear_all
134
- @tasks = Hash.new
135
- @completed_count = 0
136
- @count = 0
137
- puts "Cleared list."
138
- else
139
- puts "Cleared completed tasks."
140
- end
141
- update
142
- end
143
-
144
- # Class method that removes a list from the your lists.
145
- #
146
- # @param [string] name name of the list that you are trying to remove
147
- def self.remove name
148
- underscore_name = name.downcase.gsub(/ /, '_')
149
- begin
150
- FileUtils.rm File.join(Config[:lists_directory], underscore_name +'.yml')
151
- puts "Removed list #{name}"
152
- rescue
153
- puts "List doesn't exist"
154
- end
155
- if underscore_name == Config[:working_list_name]
156
- Config[:working_list_exists] = false
157
- end
158
- end
159
- end
160
- end
161
-