goldie 0.0.1 → 0.0.2
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.
- data/Gemfile.lock +4 -0
- data/README.md +34 -0
- data/bin/goldie +7 -3
- data/goldie.gemspec +6 -6
- data/lib/goldie.rb +2 -0
- data/lib/goldie/commands.rb +100 -26
- data/lib/goldie/database.rb +1 -1
- data/lib/goldie/item.rb +37 -4
- metadata +38 -4
data/Gemfile.lock
CHANGED
@@ -4,7 +4,9 @@ PATH
|
|
4
4
|
goldie (0.0.1)
|
5
5
|
activerecord
|
6
6
|
bundler
|
7
|
+
smart_colored
|
7
8
|
sqlite3
|
9
|
+
terminal-table
|
8
10
|
|
9
11
|
GEM
|
10
12
|
remote: http://rubygems.org/
|
@@ -25,7 +27,9 @@ GEM
|
|
25
27
|
i18n (0.6.1)
|
26
28
|
multi_json (1.3.6)
|
27
29
|
rake (0.9.2.2)
|
30
|
+
smart_colored (1.1.1)
|
28
31
|
sqlite3 (1.3.6)
|
32
|
+
terminal-table (1.4.5)
|
29
33
|
tzinfo (0.3.33)
|
30
34
|
|
31
35
|
PLATFORMS
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Goldie
|
2
|
+
|
3
|
+
Goldie is a command line todo list with lots of progress bars. Progress is its middle name.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
$ gem install goldie
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Run it like this:
|
12
|
+
|
13
|
+
$ goldie
|
14
|
+
|
15
|
+
It will set up the database in a folder called .goldie in your $HOME. Then you
|
16
|
+
can start adding todo items:
|
17
|
+
|
18
|
+
$ goldie add "take out the trash"
|
19
|
+
|
20
|
+
This adds an item with a default weight of 1. The weight of each item determines
|
21
|
+
how much it affects your overall progress bar. It can be any integer. I like to
|
22
|
+
set the weight to the number of minutes I think each task will take me.
|
23
|
+
|
24
|
+
$ goldie add "read chapter 5" 60
|
25
|
+
|
26
|
+
Then if I get that task half done, I can mark it as such:
|
27
|
+
|
28
|
+
$ goldie done 2 30
|
29
|
+
|
30
|
+
This marks task #2 as 30 minutes done, out of 60.
|
31
|
+
|
32
|
+
There are many more commands. Commands are simply Ruby methods. You can use the
|
33
|
+
'help' command to list them all, or read lib/goldie/commands.rb for details, for
|
34
|
+
now.
|
data/bin/goldie
CHANGED
@@ -13,6 +13,10 @@ DB_PATH = File.join(DIR, "todo.sqlite3")
|
|
13
13
|
|
14
14
|
db = Goldie::Database.new(DB_ADAPTER, DB_PATH)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
Goldie::Commands.
|
16
|
+
if ARGV.empty?
|
17
|
+
Goldie::Commands.list_progress
|
18
|
+
elsif not Goldie::Commands::COMMAND_LIST.keys.map(&:to_s).include? ARGV.first
|
19
|
+
puts "Nonexistant command '#{ARGV.first}'. Type 'goldie help' for help."
|
20
|
+
else
|
21
|
+
Goldie::Commands.send(*ARGV)
|
22
|
+
end
|
data/goldie.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "goldie"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.date = "2012-09-
|
5
|
-
s.summary = "A todo list
|
6
|
-
s.description = "Goldie is a
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2012-09-22"
|
5
|
+
s.summary = "A command line todo list."
|
6
|
+
s.description = "Goldie is a command line todo list with lots of progress bars. Progress is its middle name."
|
7
7
|
s.author = "Jeremy Ruten"
|
8
8
|
s.email = "jeremy.ruten@gmail.com"
|
9
9
|
s.homepage = "http://github.com/yjerem/goldie"
|
@@ -11,11 +11,11 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.required_ruby_version = ">= 1.9.2"
|
12
12
|
s.executables << "goldie"
|
13
13
|
|
14
|
-
s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "goldie.gemspec"]
|
14
|
+
s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "goldie.gemspec", "README.md"]
|
15
15
|
s.files += ["bin/goldie"]
|
16
16
|
s.files += Dir["lib/**/*.rb"]
|
17
17
|
|
18
|
-
%w(bundler sqlite3 activerecord).each do |gem_name|
|
18
|
+
%w(bundler sqlite3 activerecord smart_colored terminal-table).each do |gem_name|
|
19
19
|
s.add_runtime_dependency gem_name
|
20
20
|
end
|
21
21
|
|
data/lib/goldie.rb
CHANGED
data/lib/goldie/commands.rb
CHANGED
@@ -1,53 +1,104 @@
|
|
1
1
|
module Goldie
|
2
2
|
module Commands
|
3
|
+
COMMAND_LIST = {
|
4
|
+
add: "create a new item",
|
5
|
+
update: "modify an item",
|
6
|
+
done: "mark an item as done",
|
7
|
+
not_done: "mark an item as not done",
|
8
|
+
archive: "archive an item",
|
9
|
+
unarchive: "unarchive an item",
|
10
|
+
delete: "delete an item",
|
11
|
+
list: "list certain items",
|
12
|
+
progress: "show progress bar",
|
13
|
+
list_progress: "list items and show progress bar",
|
14
|
+
help: "list available commands"
|
15
|
+
}
|
16
|
+
|
3
17
|
extend self
|
4
18
|
|
5
19
|
def add(title, weight = 1)
|
6
20
|
item = Item.new(title: title, weight: weight)
|
7
21
|
if item.save
|
8
|
-
puts "
|
22
|
+
puts "Added item ##{item.id}."
|
23
|
+
puts
|
24
|
+
list_progress
|
9
25
|
else
|
10
26
|
puts "Item couldn't be saved:"
|
11
|
-
item
|
12
|
-
|
13
|
-
|
27
|
+
_display_errors(item)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def update(id, field, value)
|
32
|
+
if item = _find_item(id)
|
33
|
+
if %w(title weight weight_completed).include? field
|
34
|
+
if item.update_attributes(field => value)
|
35
|
+
puts "Updated item ##{item.id}."
|
36
|
+
puts
|
37
|
+
list_progress
|
38
|
+
else
|
39
|
+
puts "Item couldn't be updated:"
|
40
|
+
_display_errors(item)
|
14
41
|
end
|
42
|
+
else
|
43
|
+
puts "Item couldn't be updated:"
|
44
|
+
puts "- #{field} isn't a valid field"
|
15
45
|
end
|
16
46
|
end
|
17
47
|
end
|
18
48
|
|
19
|
-
def
|
49
|
+
def done(id, weight_completed = nil)
|
20
50
|
if item = _find_item(id)
|
21
|
-
|
22
|
-
|
51
|
+
if weight_completed
|
52
|
+
if item.update_attributes(weight_completed: weight_completed)
|
53
|
+
puts "Item ##{item.id} updated."
|
54
|
+
puts
|
55
|
+
list_progress
|
56
|
+
else
|
57
|
+
puts "Item couldn't be updated:"
|
58
|
+
_display_errors(item)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
item.done!
|
62
|
+
puts "Item ##{item.id} marked as done."
|
63
|
+
puts
|
64
|
+
list_progress
|
65
|
+
end
|
23
66
|
end
|
24
67
|
end
|
25
68
|
|
26
|
-
def
|
69
|
+
def not_done(id)
|
27
70
|
if item = _find_item(id)
|
28
|
-
item.
|
29
|
-
puts "Item
|
71
|
+
item.not_done!
|
72
|
+
puts "Item ##{item.id} marked as not done."
|
73
|
+
puts
|
74
|
+
list_progress
|
30
75
|
end
|
31
76
|
end
|
32
77
|
|
33
78
|
def archive(id)
|
34
79
|
if item = _find_item(id)
|
35
|
-
item.
|
36
|
-
puts "
|
80
|
+
item.archive!
|
81
|
+
puts "Archived item ##{item.id}."
|
82
|
+
puts
|
83
|
+
list_progress
|
37
84
|
end
|
38
85
|
end
|
39
86
|
|
40
87
|
def unarchive(id)
|
41
88
|
if item = _find_item(id)
|
42
|
-
item.
|
43
|
-
puts "
|
89
|
+
item.unarchive!
|
90
|
+
puts "Unarchived item ##{item.id}."
|
91
|
+
puts
|
92
|
+
list_progress
|
44
93
|
end
|
45
94
|
end
|
46
95
|
|
47
96
|
def delete(id)
|
48
97
|
if item = _find_item(id)
|
49
98
|
item.destroy
|
50
|
-
puts "
|
99
|
+
puts "Deleted item ##{item.id}."
|
100
|
+
puts
|
101
|
+
list_progress
|
51
102
|
end
|
52
103
|
end
|
53
104
|
|
@@ -58,16 +109,16 @@ module Goldie
|
|
58
109
|
elsif not flags.include? "all"
|
59
110
|
items = Item.active
|
60
111
|
end
|
61
|
-
|
62
|
-
|
63
|
-
else
|
64
|
-
puts "id\tweight\titem"
|
112
|
+
|
113
|
+
table = Terminal::Table.new(title: "Todo List", headings: %w(ID Progress Item)) do |t|
|
65
114
|
items.each do |item|
|
115
|
+
progress = "%d / %d" % [item.weight_completed, item.weight]
|
116
|
+
progress_bar = _render_progress_bar(item.percent_done, 10)
|
66
117
|
archived = item.archived? ? "[A] " : ""
|
67
|
-
|
68
|
-
puts "#{item.id}\t#{item.weight}\t#{done}#{archived}#{item.title}"
|
118
|
+
t.add_row [item.id, progress, "#{progress_bar} #{archived}#{item.title}"]
|
69
119
|
end
|
70
120
|
end
|
121
|
+
puts table
|
71
122
|
end
|
72
123
|
|
73
124
|
def progress
|
@@ -75,15 +126,15 @@ module Goldie
|
|
75
126
|
puts "No active items."
|
76
127
|
else
|
77
128
|
total_weight = Item.active.sum(:weight)
|
78
|
-
|
79
|
-
percent =
|
80
|
-
puts "
|
129
|
+
total_weight_completed = Item.active.sum(:weight_completed)
|
130
|
+
percent = total_weight_completed * 100 / total_weight
|
131
|
+
puts "%s %s%%" % [_render_progress_bar(percent, 50), percent]
|
81
132
|
end
|
82
133
|
end
|
83
134
|
|
84
|
-
def
|
135
|
+
def list_progress
|
85
136
|
if Item.active.empty?
|
86
|
-
puts "
|
137
|
+
puts "There are no active items to list."
|
87
138
|
else
|
88
139
|
list
|
89
140
|
puts
|
@@ -91,6 +142,16 @@ module Goldie
|
|
91
142
|
end
|
92
143
|
end
|
93
144
|
|
145
|
+
def help
|
146
|
+
puts "Usage: goldie [command] [arg1] [arg2] ..."
|
147
|
+
puts
|
148
|
+
puts "Available commands:"
|
149
|
+
puts
|
150
|
+
COMMAND_LIST.each do |command, summary|
|
151
|
+
puts " % -16s %s" % [command, summary]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
94
155
|
def _find_item(id)
|
95
156
|
if item = Item.where(id: id).first
|
96
157
|
item
|
@@ -98,5 +159,18 @@ module Goldie
|
|
98
159
|
puts "Couldn't find item with id '#{id}'."
|
99
160
|
end
|
100
161
|
end
|
162
|
+
|
163
|
+
def _display_errors(item)
|
164
|
+
item.errors.messages.each do |field, messages|
|
165
|
+
messages.each do |message|
|
166
|
+
puts "- #{field} #{message}"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def _render_progress_bar(percent, width)
|
172
|
+
progress = (percent * width / 100).to_i
|
173
|
+
("\u2589" * progress).colored.green.bold + ("\u2589" * (width - progress)).colored.white.bold
|
174
|
+
end
|
101
175
|
end
|
102
176
|
end
|
data/lib/goldie/database.rb
CHANGED
@@ -11,7 +11,7 @@ module Goldie
|
|
11
11
|
create_table :items do |t|
|
12
12
|
t.string :title, null: false
|
13
13
|
t.integer :weight, null: false, default: 1
|
14
|
-
t.
|
14
|
+
t.integer :weight_completed, null: false, default: 0
|
15
15
|
t.boolean :archived, null: false, default: false
|
16
16
|
t.timestamps
|
17
17
|
end
|
data/lib/goldie/item.rb
CHANGED
@@ -1,14 +1,47 @@
|
|
1
1
|
module Goldie
|
2
2
|
class Item < ActiveRecord::Base
|
3
|
-
attr_accessible :title, :weight, :
|
3
|
+
attr_accessible :title, :weight, :weight_completed, :archived
|
4
4
|
|
5
5
|
validates :title, presence: true
|
6
|
-
validates :weight, numericality: { only_integer: true }
|
6
|
+
validates :weight, :weight_completed, numericality: { only_integer: true }
|
7
|
+
validate :weight_completed_must_be_between_zero_and_weight
|
7
8
|
|
8
9
|
scope :archived, where(archived: true)
|
9
10
|
scope :active, where(archived: false)
|
10
|
-
scope :done, where(
|
11
|
-
scope :not_done, where(
|
11
|
+
scope :done, where("items.weight_completed == items.weight")
|
12
|
+
scope :not_done, where("items.weight_completed != items.weight")
|
12
13
|
scope :latest, order("items.created_at DESC")
|
14
|
+
|
15
|
+
def done?
|
16
|
+
weight_completed == weight
|
17
|
+
end
|
18
|
+
|
19
|
+
def done!
|
20
|
+
update_attributes!(weight_completed: weight)
|
21
|
+
end
|
22
|
+
|
23
|
+
def not_done!
|
24
|
+
update_attributes!(weight_completed: 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def archive!
|
28
|
+
update_attributes!(:archived, true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def unarchive!
|
32
|
+
update_attributes!(:archived, false)
|
33
|
+
end
|
34
|
+
|
35
|
+
def percent_done
|
36
|
+
weight_completed * 100.0 / weight
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def weight_completed_must_be_between_zero_and_weight
|
42
|
+
unless (0..weight).include? weight_completed
|
43
|
+
errors.add(:weight_completed, "must be between zero and weight")
|
44
|
+
end
|
45
|
+
end
|
13
46
|
end
|
14
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goldie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.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: 2012-09-
|
12
|
+
date: 2012-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,6 +59,38 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: smart_colored
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: terminal-table
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
62
94
|
- !ruby/object:Gem::Dependency
|
63
95
|
name: rake
|
64
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +107,8 @@ dependencies:
|
|
75
107
|
- - ! '>='
|
76
108
|
- !ruby/object:Gem::Version
|
77
109
|
version: '0'
|
78
|
-
description: Goldie is a
|
110
|
+
description: Goldie is a command line todo list with lots of progress bars. Progress
|
111
|
+
is its middle name.
|
79
112
|
email: jeremy.ruten@gmail.com
|
80
113
|
executables:
|
81
114
|
- goldie
|
@@ -86,6 +119,7 @@ files:
|
|
86
119
|
- Gemfile.lock
|
87
120
|
- LICENSE
|
88
121
|
- goldie.gemspec
|
122
|
+
- README.md
|
89
123
|
- bin/goldie
|
90
124
|
- lib/goldie/commands.rb
|
91
125
|
- lib/goldie/database.rb
|
@@ -115,5 +149,5 @@ rubyforge_project:
|
|
115
149
|
rubygems_version: 1.8.23
|
116
150
|
signing_key:
|
117
151
|
specification_version: 3
|
118
|
-
summary: A todo list
|
152
|
+
summary: A command line todo list.
|
119
153
|
test_files: []
|