todd 0.0.9

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/lib/todd/util.rb ADDED
@@ -0,0 +1,151 @@
1
+ module Todd
2
+ class Util
3
+ def self.needs file
4
+ begin
5
+ require file
6
+ rescue LoadError => e
7
+ warn "Cannot find module %s, perhaps you need to install it?" % file
8
+ exit
9
+ end
10
+ end
11
+
12
+ def self.time_period_to_s time_period
13
+ time_period = time_period.to_i
14
+
15
+ if time_period < 1
16
+ return "< 1 sec"
17
+ end
18
+
19
+ out_str = ''
20
+ interval_array = [ [:weeks, 604800], [:days, 86400], [:hours, 3600], [:mins, 60], [:secs, 1] ]
21
+ interval_array.each do |sub|
22
+ if time_period >= sub[1] then
23
+ time_val, time_period = time_period.divmod( sub[1] )
24
+ time_val == 1 ? name = sub[0].to_s.singularize : name = sub[0].to_s
25
+ ( sub[0] != :mins ? out_str += ", " : out_str += " and " ) if out_str != ''
26
+ out_str += time_val.to_s + " #{name}"
27
+ end
28
+ end
29
+
30
+ out_str
31
+ end
32
+
33
+ def self.to_minimal_time_s time_period
34
+ time_period = time_period.to_i
35
+
36
+ out_str = ''
37
+ interval_array = [3600, 60, 1]
38
+ interval_array.each do |sub|
39
+ if time_period >= sub then
40
+ time_val, time_period = time_period.divmod(sub)
41
+ out_str += "%02d" % time_val
42
+ else
43
+ out_str += "00"
44
+ end
45
+ out_str += ":" if sub != interval_array[-1]
46
+ end
47
+
48
+ out_str
49
+ end
50
+
51
+ def self.format_bundle bundle, formatting = nil
52
+ formatting = Base[:output_format] unless formatting
53
+ case formatting
54
+ when "table"
55
+ needs 'terminal-table/import'
56
+ return self.format_to_table bundle
57
+ when "minimal"
58
+ return self.format_minimal bundle
59
+ when "ruby_obj"
60
+ return PP.pp(bundle,'')
61
+ when "json"
62
+ needs 'json'
63
+ return bundle.to_json
64
+ else
65
+ puts "ERROR: Cannot format bundle to #{formatting}"
66
+ exit
67
+ end
68
+ end
69
+
70
+ def self.format_to_table stack, ret_table = true
71
+ stack = [stack] unless stack.class == [].class
72
+ rows = []
73
+ header = ["ID", "Task", "Session Time", "Total Time"]
74
+
75
+ while item = stack.pop
76
+ case item[:type]
77
+ when :todolist
78
+ return "" if item[:categories] == []
79
+ stack = item[:categories]
80
+ when :category
81
+ return "" if item[:task] == []
82
+ rows << ['Category:',item[:name],'','']
83
+ rows << :separator
84
+ rows += self.format_to_table item[:tasks], false
85
+ rows << :separator unless stack.empty?
86
+ when :task
87
+ running = item[:active]
88
+ rows << [
89
+ item[:id],
90
+ item[:title],
91
+ running ? self.time_period_to_s(item[:session_time]) : 'Not Running',
92
+ item[:total_time].to_i > 0.1 ? self.time_period_to_s(item[:total_time].to_i) : 'Never Run'
93
+ ]
94
+ else
95
+ puts "ERROR: Bundle type #{bundle[:type]} not recognized"
96
+ exit
97
+ end
98
+ end
99
+
100
+ return rows unless ret_table
101
+
102
+ table(header, *rows)
103
+ end
104
+
105
+ def self.format_minimal stack, ret_string = true
106
+ stack = [stack] unless stack.class == [].class
107
+ rows = []
108
+ default_category = Base[:default_category]
109
+
110
+ while item = stack.pop
111
+ case item[:type]
112
+ when :todolist
113
+ return "Nothing to list" if item[:categories] == []
114
+ stack = item[:categories]
115
+ stack.sort! do |x,y|
116
+ case default_category
117
+ when x[:name]
118
+ ret = 1
119
+ when y[:name]
120
+ ret = -1
121
+ else
122
+ ret = x[:name] <=> y[:name]
123
+ end
124
+ ret
125
+ end
126
+ when :category
127
+ return "" if item[:task] == []
128
+ rows << "+ #{item[:name]}" unless item[:name] == Base[:default_category]
129
+ rows += self.format_minimal item[:tasks], false
130
+ rows << " " unless stack.empty?
131
+ when :task
132
+ rows << [
133
+ item[:id],
134
+ item[:active] ? 'x' : ' ',
135
+ self.to_minimal_time_s(item[:total_time]),
136
+ item[:title]
137
+ ].map { |e|
138
+ "[%s]" % e
139
+ } * " " + (item[:active] ? " [%s]" % self.to_minimal_time_s(item[:session_time]) : '')
140
+ else
141
+ puts "ERROR: Bundle type #{bundle[:type]} not recognized"
142
+ exit
143
+ end
144
+ end
145
+
146
+ return rows unless ret_string
147
+
148
+ rows * "\n"
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,3 @@
1
+ module Todd
2
+ VERSION = '0.0.9'
3
+ end
@@ -0,0 +1,5 @@
1
+ task :enviroment do
2
+ ActiveRecord::Base.establish_connection(YAML::load(File.open('db/database.yml')))
3
+ ActiveRecord::Base.logger = Logger.new(File.open('logs/migrations.log', 'a'))
4
+ ActiveRecord::Base.colorize_logging = false
5
+ end
@@ -0,0 +1,4 @@
1
+ desc "Migrate the DB file to the latest migration. Will create the DB file if it does not exist."
2
+ task :migrate => :enviroment do
3
+ ActiveRecord::Migrator.migrate('db/migrations',nil)
4
+ end
@@ -0,0 +1,17 @@
1
+ desc "Create a new migration file in db/migrations"
2
+ task :migration do
3
+ migration_name = ask("Migration Name (Uppercase+Spaces): ")
4
+ klass_name = migration_name.gsub(/\s/, '')
5
+ file_name = migration_name.downcase.gsub(/\s/, '_')
6
+ File.open(Time.now.strftime("db/migrations/%m%d%y%H%M_#{file_name}.rb"), 'w') do |file|
7
+ file.write(<<-eos)
8
+ class #{klass_name} < ActiveRecord::Migration
9
+ def self.up
10
+ end
11
+
12
+ def self.down
13
+ end
14
+ end
15
+ eos
16
+ end
17
+ end
data/tasks/revert.rake ADDED
@@ -0,0 +1,5 @@
1
+ task :revert => :revert_db do
2
+ if agree("This will remove the .todd file in the local dir. Continue?")
3
+ rm '.todd'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ desc "Revert the DB to a blank slate"
2
+ task :revert_db => :enviroment do
3
+ if agree("Are you sure you want to revert the db? All data will be lost!")
4
+ rm 'db/todd.db'
5
+ Rake::Task[:migrate].execute
6
+ end
7
+ end
data/todd.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{todd}
5
+ s.version = "0.0.9"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Carl Sverre"]
9
+ s.date = %q{2010-02-22}
10
+ s.description = %q{A simple time-tracking todo-list for the command line.}
11
+ s.email = %q{carl@carlsverre.com}
12
+ s.executables = ["todd", "todd.rb", "todd_old.rb"]
13
+ s.extra_rdoc_files = ["TODO", "bin/todd", "bin/todd.rb", "bin/todd_old.rb", "lib/todd.rb", "lib/todd/config.rb", "lib/todd/model.rb", "lib/todd/util.rb", "lib/todd/version.rb", "tasks/enviroment.rake", "tasks/migrate.rake", "tasks/migration.rake", "tasks/revert.rake", "tasks/revert_db.rake"]
14
+ s.files = ["History.md", "Manifest", "Rakefile", "Readme.md", "TODO", "bin/todd", "bin/todd.rb", "bin/todd_old.rb", "db/database.yml", "db/migrations/0214102019_initialize_database.rb", "db/migrations/0221102255_add_punch_table.rb", "db/migrations/0222102121_remove_archived_tasks.rb", "db/migrations/0222102124_add_archived_column_to_tasks.rb", "db/todd.db", "lib/todd.rb", "lib/todd/config.rb", "lib/todd/model.rb", "lib/todd/util.rb", "lib/todd/version.rb", "tasks/enviroment.rake", "tasks/migrate.rake", "tasks/migration.rake", "tasks/revert.rake", "tasks/revert_db.rake", "todd.gemspec"]
15
+ s.homepage = %q{http://github.com/uvic-sdo/todd}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Todd", "--main", "Readme.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{todd}
19
+ s.rubygems_version = %q{1.3.5}
20
+ s.summary = %q{A simple time-tracking todo-list for the command line.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<commander>, [">= 4.0.2"])
28
+ s.add_runtime_dependency(%q<active_record>, [">= 2.3.5"])
29
+ s.add_runtime_dependency(%q<terminal_table>, [">= 1.4.2"])
30
+ s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
31
+ else
32
+ s.add_dependency(%q<commander>, [">= 4.0.2"])
33
+ s.add_dependency(%q<active_record>, [">= 2.3.5"])
34
+ s.add_dependency(%q<terminal_table>, [">= 1.4.2"])
35
+ s.add_dependency(%q<json>, [">= 1.2.0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<commander>, [">= 4.0.2"])
39
+ s.add_dependency(%q<active_record>, [">= 2.3.5"])
40
+ s.add_dependency(%q<terminal_table>, [">= 1.4.2"])
41
+ s.add_dependency(%q<json>, [">= 1.2.0"])
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Carl Sverre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-22 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: commander
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 4.0.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_record
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.5
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: terminal_table
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: json
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.0
54
+ version:
55
+ description: A simple time-tracking todo-list for the command line.
56
+ email: carl@carlsverre.com
57
+ executables:
58
+ - todd
59
+ - todd.rb
60
+ - todd_old.rb
61
+ extensions: []
62
+
63
+ extra_rdoc_files:
64
+ - TODO
65
+ - bin/todd
66
+ - bin/todd.rb
67
+ - bin/todd_old.rb
68
+ - lib/todd.rb
69
+ - lib/todd/config.rb
70
+ - lib/todd/model.rb
71
+ - lib/todd/util.rb
72
+ - lib/todd/version.rb
73
+ - tasks/enviroment.rake
74
+ - tasks/migrate.rake
75
+ - tasks/migration.rake
76
+ - tasks/revert.rake
77
+ - tasks/revert_db.rake
78
+ files:
79
+ - History.md
80
+ - Manifest
81
+ - Rakefile
82
+ - Readme.md
83
+ - TODO
84
+ - bin/todd
85
+ - bin/todd.rb
86
+ - bin/todd_old.rb
87
+ - db/database.yml
88
+ - db/migrations/0214102019_initialize_database.rb
89
+ - db/migrations/0221102255_add_punch_table.rb
90
+ - db/migrations/0222102121_remove_archived_tasks.rb
91
+ - db/migrations/0222102124_add_archived_column_to_tasks.rb
92
+ - db/todd.db
93
+ - lib/todd.rb
94
+ - lib/todd/config.rb
95
+ - lib/todd/model.rb
96
+ - lib/todd/util.rb
97
+ - lib/todd/version.rb
98
+ - tasks/enviroment.rake
99
+ - tasks/migrate.rake
100
+ - tasks/migration.rake
101
+ - tasks/revert.rake
102
+ - tasks/revert_db.rake
103
+ - todd.gemspec
104
+ has_rdoc: true
105
+ homepage: http://github.com/uvic-sdo/todd
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options:
110
+ - --line-numbers
111
+ - --inline-source
112
+ - --title
113
+ - Todd
114
+ - --main
115
+ - Readme.md
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ version:
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "1.2"
129
+ version:
130
+ requirements: []
131
+
132
+ rubyforge_project: todd
133
+ rubygems_version: 1.3.5
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: A simple time-tracking todo-list for the command line.
137
+ test_files: []
138
+