timesheets 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 241b39acbe35ef74faa2c26862450110707d6e7f
4
+ data.tar.gz: e8034b7b0ff1da83f69ce7a8543b4801ff4b560b
5
+ SHA512:
6
+ metadata.gz: 791d4e86169ca723076c548a6e154c9267473cf5413a4ed0bf858d842706af447477a283902b16c636ce2ce5d68f461929f4b7b8588f8d157b31387e71f25737
7
+ data.tar.gz: e3657439a1b06d7122b2c21ebc6b1fdc51da25955e4c15bfa6e0718e37fe3ab5b58c4f8ce965859cf15b9f6ffdacf2693cf9f0e80b617d54a13353f172db8c53
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in timesheets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Bradley J. Spaulding
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,80 @@
1
+ # Timesheets
2
+
3
+ A CLI for managing timesheets.
4
+
5
+ ## Installation
6
+
7
+ Install it via RubyGems:
8
+
9
+ $ gem install timesheets
10
+
11
+ ## Usage
12
+
13
+ ### Help / Commands
14
+
15
+ Run `timesheets` to see a list of available commands:
16
+
17
+ $ timesheets
18
+ Commands:
19
+ timesheets edit # Manually edit timesheet data
20
+ timesheets help [COMMAND] # Describe available commands or one specific command
21
+ timesheets start # Begin a work session
22
+ timesheets status # Show current work status
23
+ timesheets stop # End the current work session
24
+ timesheets summary # See a summary table of time worked
25
+
26
+
27
+ ### Edit
28
+
29
+ Opens the underlying spreadsheet (CSV) in your configured editor. Tries `$EDITOR`, then `git config core.editor`, then defaults to `vim`.
30
+
31
+ $ timesheets edit
32
+
33
+ ### Start
34
+
35
+ Starts a session.
36
+
37
+ $ timesheets start
38
+ Started session at 2014-05-04 13:47:33 -0500
39
+
40
+ ### Status
41
+
42
+ Shows the status of the current work session, if any.
43
+
44
+ $ timesheets status
45
+ Current work session has been active for 8 minutes
46
+
47
+ ### Stop
48
+
49
+ Ends the current work session, if any.
50
+
51
+ $ timesheets stop
52
+ Ended session at 2014-05-04 14:38:42 -0500
53
+
54
+ ### Summary
55
+
56
+ A neat ASCII table report, including total hours.
57
+
58
+ $ timesheets summary
59
+ +-----------+----------------+------------+----------+---------+
60
+ | Weekday | Date | Start Time | End Time | Hour(s) |
61
+ +-----------+----------------+------------+----------+---------+
62
+ | Monday | April 28, 2014 | 12:00PM | 8:00PM | 8.0 |
63
+ | Monday | April 28, 2014 | 11:00AM | 8:00PM | 9.0 |
64
+ | Tuesday | April 29, 2014 | 11:00AM | 2:00PM | 3.0 |
65
+ | Tuesday | April 29, 2014 | 2:30PM | 8:30PM | 6.0 |
66
+ | Wednesday | April 30, 2014 | 11:00AM | 7:00PM | 8.0 |
67
+ | Thursday | May 1, 2014 | 10:15AM | 6:45PM | 8.5 |
68
+ | Friday | May 2, 2014 | 10:30AM | 12:30PM | 2.0 |
69
+ | Friday | May 2, 2014 | 2:30PM | 7:15PM | 4.75 |
70
+ +-----------+----------------+------------+----------+---------+
71
+ | | | | | 49.25 |
72
+ +-----------+----------------+------------+----------+---------+
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it (https://github.com/bspaulding/timesheets/fork)
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new {|t|
5
+ t.test_files = FileList['spec/spec_helper.rb', 'spec/**/*_spec.rb']
6
+ }
7
+
data/bin/timesheets ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'timesheets'
4
+
5
+ Timesheets::CLI.start(ARGV)
data/lib/timesheets.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Timesheets; end
2
+
3
+ require "timesheets/version"
4
+ require "timesheets/cli"
@@ -0,0 +1,40 @@
1
+ require 'thor'
2
+ require 'terminal-table'
3
+ require 'csv'
4
+
5
+ require "timesheets/commands/base"
6
+ require "timesheets/commands/edit"
7
+ require "timesheets/commands/start"
8
+ require "timesheets/commands/status"
9
+ require "timesheets/commands/stop"
10
+ require "timesheets/commands/summary"
11
+
12
+ module Timesheets
13
+ class CLI < Thor
14
+ desc "edit", "Manually edit timesheet data"
15
+ def edit
16
+ Commands::Edit.run
17
+ end
18
+
19
+ desc "start", "Begin a work session"
20
+ def start
21
+ Commands::Start.run
22
+ end
23
+
24
+ desc "status", "Show current work status"
25
+ def status
26
+ Commands::Status.run
27
+ end
28
+
29
+ desc "stop", "End the current work session"
30
+ def stop
31
+ Commands::Stop.run
32
+ end
33
+
34
+ desc "summary", "See a summary table of time worked"
35
+ def summary
36
+ Commands::Summary.run
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,31 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Base
4
+ def self.run
5
+ new.run
6
+ end
7
+
8
+ private
9
+
10
+ def session_in_progress?
11
+ rows.last.last.nil?
12
+ end
13
+
14
+ def hours_in_entry(entry)
15
+ entry.map(&:to_i).reverse.reduce(:-) / 3600.0
16
+ end
17
+
18
+ def entries
19
+ @entries ||= rows.map {|row| row.map {|dt| DateTime.parse(dt || Time.now.to_s).to_time } }
20
+ end
21
+
22
+ def rows
23
+ @rows ||= CSV.read(filepath)[1..-1]
24
+ end
25
+
26
+ def filepath
27
+ File.expand_path(ENV['TIMESHEETS_FILEPATH'] || '~/.timesheets.csv')
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Edit < Base
4
+ def run
5
+ exec("#{editor} #{filepath}")
6
+ end
7
+
8
+ private
9
+
10
+ def editor
11
+ env_editor || git_editor || 'vim'
12
+ end
13
+
14
+ def env_editor
15
+ env_editor_set? && env_editor_name
16
+ end
17
+
18
+ def env_editor_set?
19
+ env_editor_name.length > 0
20
+ end
21
+
22
+ def env_editor_name
23
+ ENV['EDITOR'].to_s
24
+ end
25
+
26
+ def git_editor
27
+ git? && git_editor_set? && git_editor_name
28
+ end
29
+
30
+ def git?
31
+ %x[which git].length > 0
32
+ end
33
+
34
+ def git_editor_set?
35
+ git_editor_name.length > 0
36
+ end
37
+
38
+ def git_editor_name
39
+ %x[git config core.editor]
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Start < Base
4
+ def run
5
+ if session_in_progress?
6
+ puts "Session already in progress"
7
+ else
8
+ time = Time.new
9
+ add_new_entry(time)
10
+ puts "Started session at #{time}"
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def add_new_entry(time)
17
+ File.open(filepath, 'a') {|f| f.write("#{time},") }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Status < Base
4
+ def run
5
+ if session_in_progress?
6
+ puts "Current work session has been active for #{active_time}"
7
+ else
8
+ puts "Not currently working"
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def active_time
15
+ hoursf = hours_in_entry(entries.last)
16
+ hours = hoursf.to_i
17
+ mins = ((hoursf - hours) * 60).to_i
18
+
19
+ [pluralize('hour', hours), pluralize('minute', mins)]
20
+ .reject {|string| string[0] == "0" }
21
+ .join(', ')
22
+ end
23
+
24
+ def pluralize(word, n)
25
+ n == 1 && "#{n} #{word}" || "#{n} #{word}s"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,23 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Stop < Base
4
+ def run
5
+ if session_in_progress?
6
+ time = Time.new
7
+ close_last_entry(time)
8
+ puts "Ended session at #{time}"
9
+ else
10
+ puts "No session in progress"
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def close_last_entry(time)
17
+ File.open(filepath, 'a') {|f| f.write("#{time}\n") }
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,38 @@
1
+ module Timesheets
2
+ module Commands
3
+ class Summary < Base
4
+ def run
5
+ puts summary_table
6
+ end
7
+
8
+ private
9
+
10
+ def summary_table
11
+ Terminal::Table.new(headings: ['Weekday', 'Date', 'Start Time', 'End Time', 'Hour(s)']) {|t|
12
+ formatted_entries.each {|entry| t << entry }
13
+ t << :separator
14
+ t << (formatted_entries.first.length - 1).times.map { '' } + [sprintf('%0.02f', total_hours)]
15
+
16
+ formatted_entries.first.length.times {|i| t.align_column(i, :right) }
17
+ }
18
+ end
19
+
20
+ def total_hours
21
+ entries.map {|entry| hours_in_entry(entry) }.reduce(:+)
22
+ end
23
+
24
+ def formatted_entries
25
+ @formatted_entries ||= entries.map {|entry|
26
+ [
27
+ entry.first.strftime('%A'),
28
+ entry.first.strftime('%B %e, %Y'),
29
+ entry.map {|time|
30
+ time.strftime('%l:%M%p')
31
+ },
32
+ sprintf('%0.02f', hours_in_entry(entry))
33
+ ].flatten
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Timesheets
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'timesheets'
5
+ require 'minitest/autorun'
6
+
7
+ TIMESHEETS_FILEPATH='./tmp/timesheets.csv'
8
+ FileUtils.mkdir_p('./tmp')
9
+ File.open(TIMESHEETS_FILEPATH, 'w+') {|f| f.write('Start,End') }
10
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'timesheets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "timesheets"
8
+ spec.version = Timesheets::VERSION
9
+ spec.authors = ["Bradley J. Spaulding"]
10
+ spec.email = ["brad.spaulding@gmail.com"]
11
+ spec.summary = %q{A CLI for managing timesheets.}
12
+ spec.description = ""
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "terminal-table"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "simplecov"
27
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timesheets
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bradley J. Spaulding
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - brad.spaulding@gmail.com
86
+ executables:
87
+ - timesheets
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/timesheets
97
+ - lib/timesheets.rb
98
+ - lib/timesheets/cli.rb
99
+ - lib/timesheets/commands/base.rb
100
+ - lib/timesheets/commands/edit.rb
101
+ - lib/timesheets/commands/start.rb
102
+ - lib/timesheets/commands/status.rb
103
+ - lib/timesheets/commands/stop.rb
104
+ - lib/timesheets/commands/summary.rb
105
+ - lib/timesheets/version.rb
106
+ - spec/spec_helper.rb
107
+ - timesheets.gemspec
108
+ homepage: ''
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A CLI for managing timesheets.
132
+ test_files:
133
+ - spec/spec_helper.rb