tdo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/tdo +7 -2
- data/lib/tdo.rb +45 -20
- data/tdo.gemspec +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/tdo
CHANGED
@@ -26,6 +26,11 @@ opts = OptionParser.new do |opts|
|
|
26
26
|
exit 0
|
27
27
|
end
|
28
28
|
|
29
|
+
opts.on("--summary", "-s", "Summary") do
|
30
|
+
puts Tdo.task_summary
|
31
|
+
exit 0
|
32
|
+
end
|
33
|
+
|
29
34
|
opts.on("--clear", "-c", "Clear done items") do
|
30
35
|
Tdo.clear_done
|
31
36
|
exit 0
|
@@ -41,9 +46,9 @@ opts.parse!
|
|
41
46
|
|
42
47
|
|
43
48
|
if ARGV.size == 2
|
44
|
-
Tdo.add_task(ARGV[1], ARGV[0]
|
49
|
+
Tdo.add_task(ARGV[1], ARGV[0])
|
45
50
|
elsif ARGV.size == 1
|
46
51
|
Tdo.add_task(ARGV[0])
|
47
52
|
else
|
48
|
-
puts
|
53
|
+
puts Tdo.task_summary
|
49
54
|
end
|
data/lib/tdo.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
module Tdo
|
3
3
|
|
4
|
+
class InvalidGroup < ArgumentError; end
|
5
|
+
|
4
6
|
TODO_FILE = File.expand_path "~/.todo.txt"
|
5
7
|
|
6
8
|
# Reads the TODO file
|
@@ -16,61 +18,84 @@ module Tdo
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
# Gives a summary of remaining tasks
|
22
|
+
#
|
23
|
+
# @return [String] summary of tasks
|
24
|
+
def self.task_summary
|
25
|
+
t = to_hash( self.read_tasks )
|
26
|
+
groups = t.size
|
27
|
+
tasks = t.inject(0) {|sum, t| sum += t[1].size}
|
28
|
+
done = t.inject(0) {|sum, t| sum += t[1].delete_if {|i| !i.include? ' #done' }.size}
|
29
|
+
"#{tasks} tasks in #{groups} groups, #{done} done"
|
30
|
+
end
|
31
|
+
|
19
32
|
# Allows you to add a new task to the file
|
20
33
|
#
|
21
34
|
# @param [String] task to add
|
22
35
|
# @param [String] group to add the task to
|
23
|
-
def self.add_task( task, group='ungrouped' )
|
36
|
+
def self.add_task( task, group='@ungrouped' )
|
24
37
|
if File.exists? TODO_FILE
|
25
38
|
t = to_hash( self.read_tasks )
|
26
39
|
else
|
27
40
|
t = {}
|
28
41
|
end
|
42
|
+
if group[0] == "@"
|
43
|
+
group = group[1..-1]
|
44
|
+
else
|
45
|
+
raise InvalidGroup, "'#{group}' is not a valid group name", caller
|
46
|
+
end
|
29
47
|
t[group] ||= [] # need to create new group if it doesn't exist
|
30
48
|
t[group] << task.strip
|
31
49
|
|
32
|
-
|
33
|
-
f.puts to_s(t)
|
50
|
+
write_hash t
|
34
51
|
end
|
35
52
|
|
36
53
|
# Marks the selected item as done
|
37
54
|
#
|
38
55
|
# @param [String, Integer] task to mark as done
|
39
56
|
# @param [String] group that the task belongs to
|
40
|
-
def self.mark_done( id, group='ungrouped' )
|
41
|
-
|
57
|
+
def self.mark_done( id, group='@ungrouped' )
|
58
|
+
if group[0] == "@"
|
59
|
+
group = group[1..-1]
|
60
|
+
else
|
61
|
+
raise InvalidGroup, "'#{group}' is not a valid group name", caller
|
62
|
+
end
|
42
63
|
|
43
64
|
t = to_hash( self.read_tasks )
|
44
|
-
if id.is_a? String
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
t[group][i] += ' #done'
|
49
|
-
end
|
65
|
+
if id.is_a? String
|
66
|
+
t[group].each_with_index do |task, i|
|
67
|
+
if task.include? id
|
68
|
+
t[group][i] += ' #done'
|
50
69
|
end
|
51
|
-
rescue
|
52
|
-
p "Group, #{group}, does not exist"
|
53
70
|
end
|
54
71
|
elsif id.is_a? Integer
|
55
72
|
t[group][id] += ' #done'
|
56
73
|
end
|
57
|
-
|
58
|
-
f = File.new(TODO_FILE, "w")
|
59
|
-
f.puts to_s(t)
|
74
|
+
write_hash t
|
60
75
|
end
|
61
76
|
|
77
|
+
|
62
78
|
# Deletes all items which have been marked done
|
63
79
|
#
|
80
|
+
# @return [Integer] number of tasks cleared
|
64
81
|
def self.clear_done
|
65
82
|
t = to_hash( self.read_tasks )
|
83
|
+
r = 0
|
66
84
|
t.each do |group, tasks|
|
67
|
-
|
85
|
+
s = tasks.size
|
86
|
+
r += tasks.delete_if {|i| i.include? ' #done' }.size - s
|
68
87
|
end
|
69
|
-
|
70
|
-
|
71
|
-
f.puts to_s(t)
|
88
|
+
write_hash t
|
89
|
+
r
|
72
90
|
end
|
73
91
|
|
92
|
+
# Converts the given hash to a string and writes to the TODO_FILE
|
93
|
+
#
|
94
|
+
# @param [Hash] tasks hash to write
|
95
|
+
def self.write_hash( hash )
|
96
|
+
f = File.new(TODO_FILE, "w")
|
97
|
+
f.puts to_s( hash )
|
98
|
+
end
|
74
99
|
|
75
100
|
# Converts the string read from the file to a hash so it can easily be used
|
76
101
|
#
|
data/tdo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{tdo}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joshua Hawxwell"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-12}
|
13
13
|
s.default_executable = %q{tdo}
|
14
14
|
s.description = %q{Tdo is a simple ruby app to add, edit and read your todo list. It stores the list at ~/.todo.txt}
|
15
15
|
s.email = %q{m@hawx.me}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Hawxwell
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-12 00:00:00 +01:00
|
18
18
|
default_executable: tdo
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|