time_cop 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/Rakefile +0 -10
- data/bin/console +1 -0
- data/lib/time_cop/accountability.rb +10 -6
- data/lib/time_cop/option_parser.rb +6 -2
- data/lib/time_cop/runner.rb +33 -1
- data/lib/time_cop/version.rb +1 -1
- data/time_cop.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c21ee81a8b7fc0e59cc8a8e5f157c5d17cfd3214
|
4
|
+
data.tar.gz: 8360109023c4c93f1f34808281b121f2a13eab73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dd03ba3806685a59503b8ab5d6c9cb1e1915d9f112986da4ad1b0e64754319149375aa376b47c1dbd8be78d13108e1847932ed23b51b1a950ab3a224fd7c573
|
7
|
+
data.tar.gz: c4266afc1f13cdaeb481dc7e8fac50997fc79a3ac50df396ec4f9948282005de53bccf089e73c8f65499cb7c79937097d8d879fa0e234bb2e1666bf14b913dbc
|
data/README.md
CHANGED
@@ -7,12 +7,13 @@ TODO: Delete this and the text above, and describe your gem
|
|
7
7
|
## Installation
|
8
8
|
$ gem install time_cop
|
9
9
|
|
10
|
+
If you are using rbenv, retstart your terminal or run:
|
11
|
+
$ rbenv rehash
|
12
|
+
|
10
13
|
And then execute:
|
11
14
|
|
12
15
|
$ time_cop
|
13
16
|
|
14
|
-
Or install it yourself as:
|
15
|
-
|
16
17
|
## Usage
|
17
18
|
|
18
19
|
$ time_cop --username=user@wild.land --password=super_secret_password
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "bundler"
|
2
|
-
require "bundler/gem_tasks"
|
3
2
|
require "rake/testtask"
|
4
3
|
|
5
4
|
Bundler::GemHelper.install_tasks
|
@@ -11,12 +10,3 @@ Rake::TestTask.new(:test) do |t|
|
|
11
10
|
end
|
12
11
|
|
13
12
|
task :default => :test
|
14
|
-
|
15
|
-
task :console do
|
16
|
-
require 'irb'
|
17
|
-
require 'irb/completion'
|
18
|
-
require 'pry'
|
19
|
-
require 'time_cop' # You know what to do.
|
20
|
-
ARGV.clear
|
21
|
-
IRB.start
|
22
|
-
end
|
data/bin/console
CHANGED
@@ -3,11 +3,9 @@ require 'date'
|
|
3
3
|
|
4
4
|
module TimeCop
|
5
5
|
class Accountability
|
6
|
-
attr_reader :report_builder, :client, :date
|
6
|
+
attr_reader :report_builder, :client, :date, :hours_per_week
|
7
7
|
|
8
8
|
DAYS_PER_WEEK = 5.0
|
9
|
-
HOURS_PER_WEEK = 32.0
|
10
|
-
HOURS_PER_DAY = HOURS_PER_WEEK / DAYS_PER_WEEK
|
11
9
|
|
12
10
|
QUARTERLY_PERIODS = {
|
13
11
|
q1: [{month: 1, day: 1}, {month: 3, day: 31}],
|
@@ -16,9 +14,10 @@ module TimeCop
|
|
16
14
|
q4: [{month: 10, day: 1}, {month: 12, day: 31}]
|
17
15
|
}
|
18
16
|
|
19
|
-
def initialize(username:, password:, subdomain: 'wildland', date: Date.today, report_builder: nil, email: nil)
|
17
|
+
def initialize(username:, password:, subdomain: 'wildland', date: Date.today, report_builder: nil, email: nil, hours_per_week: 32)
|
20
18
|
@client = Harvest.client(username: username, password: password, subdomain: subdomain)
|
21
19
|
@date = date
|
20
|
+
@hours_per_week = hours_per_week
|
22
21
|
@report_builder = report_builder ||
|
23
22
|
ReportBuilder.new(
|
24
23
|
client: client,
|
@@ -28,6 +27,10 @@ module TimeCop
|
|
28
27
|
)
|
29
28
|
end
|
30
29
|
|
30
|
+
def hours_per_day
|
31
|
+
@hours_per_week / DAYS_PER_WEEK
|
32
|
+
end
|
33
|
+
|
31
34
|
def account
|
32
35
|
client.account
|
33
36
|
end
|
@@ -126,11 +129,11 @@ module TimeCop
|
|
126
129
|
end
|
127
130
|
|
128
131
|
def expected_quarter_hours
|
129
|
-
total_week_days.to_f *
|
132
|
+
total_week_days.to_f * hours_per_day
|
130
133
|
end
|
131
134
|
|
132
135
|
def expected_quarter_hours_to_today
|
133
|
-
business_days_between(start_of_quarter_date, date) *
|
136
|
+
business_days_between(start_of_quarter_date, date) * hours_per_day
|
134
137
|
end
|
135
138
|
|
136
139
|
def current_hours_delta
|
@@ -151,6 +154,7 @@ module TimeCop
|
|
151
154
|
|
152
155
|
def print_report
|
153
156
|
puts "Quarter Period: #{start_of_quarter_date} #{end_of_quarter_date}"
|
157
|
+
puts "Hours Per Week: #{@hours_per_week}"
|
154
158
|
puts "Current Surplus(+)/Deficit(-): #{current_hours_delta.round(2)}"
|
155
159
|
puts "Quarterly Hour Target: #{expected_quarter_hours.round(2)}"
|
156
160
|
puts "Current Quarterly Charged Hours: #{total_quarter_time_tracked.round(2)}"
|
@@ -23,6 +23,10 @@ module TimeCop
|
|
23
23
|
options[:email] = email
|
24
24
|
end
|
25
25
|
|
26
|
+
opts.on('-i', '--interactive', 'Runs in interactive mode') do
|
27
|
+
options[:interactive] = true
|
28
|
+
end
|
29
|
+
|
26
30
|
opts.on("-h", "--help", "Prints help") do
|
27
31
|
puts opts
|
28
32
|
exit
|
@@ -31,8 +35,8 @@ module TimeCop
|
|
31
35
|
|
32
36
|
option_parser.parse(args)
|
33
37
|
|
34
|
-
unless options[:username] && options[:password]
|
35
|
-
puts "Please specify a username and password"
|
38
|
+
unless ((options[:username] && options[:password]) || options[:interactive])
|
39
|
+
puts "Please specify a username and password or run in interactive mode"
|
36
40
|
puts option_parser
|
37
41
|
exit
|
38
42
|
end
|
data/lib/time_cop/runner.rb
CHANGED
@@ -1,13 +1,45 @@
|
|
1
1
|
require 'time_cop/option_parser'
|
2
|
+
require 'highline'
|
3
|
+
require 'active_support/core_ext/date_and_time/calculations'
|
2
4
|
|
3
5
|
module TimeCop
|
4
6
|
class Runner
|
5
7
|
def self.invoke
|
6
8
|
options_parser = OptionParser.new(ARGV)
|
7
9
|
options = options_parser.parse
|
10
|
+
interactive_hash = {}
|
8
11
|
|
9
|
-
|
12
|
+
if (options[:interactive])
|
13
|
+
cli = HighLine.new
|
14
|
+
username = cli.ask('Harvest Username: ')
|
15
|
+
password = cli.ask('Harvest Password: ') { |q| q.echo = false }
|
16
|
+
interactive_hash[:hours_per_week] = cli.ask('Hours per week? ') { |q| q.default = 32 }.to_i
|
17
|
+
cli.choose do |menu|
|
18
|
+
menu.prompt = 'Which Quarter? '
|
19
|
+
menu.choice(:Q1) { interactive_hash[:date] = Date.new(Date.today.year, 1, 1)}
|
20
|
+
menu.choice(:Q2) { interactive_hash[:date] = Date.new(Date.today.year, 4, 1)}
|
21
|
+
menu.choice(:Q3) { interactive_hash[:date] = Date.new(Date.today.year, 7, 1)}
|
22
|
+
menu.choice(:Q4) { interactive_hash[:date] = Date.new(Date.today.year, 10, 1)}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
accountability_options = {
|
27
|
+
username: (username.nil? ? options[:username] : username),
|
28
|
+
password: (password.nil? ? options[:password] : password),
|
29
|
+
email: options[:email]
|
30
|
+
}
|
31
|
+
|
32
|
+
accountability_options = interactive_hash.merge(accountability_options)
|
33
|
+
|
34
|
+
accountability = Accountability.new(
|
35
|
+
accountability_options
|
36
|
+
)
|
10
37
|
accountability.print_report
|
38
|
+
rescue Harvest::AuthenticationFailed
|
39
|
+
puts 'Unable to authenticate to Harvest. Check username/password.'
|
40
|
+
rescue Harvest::HTTPError => e
|
41
|
+
puts 'Harvest API Error'
|
42
|
+
puts e.to_s
|
11
43
|
end
|
12
44
|
end
|
13
45
|
end
|
data/lib/time_cop/version.rb
CHANGED
data/time_cop.gemspec
CHANGED
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
32
|
spec.add_runtime_dependency "harvested", "~> 3.1.1"
|
33
|
+
spec.add_runtime_dependency "highline", "~> 1.7.8"
|
34
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.0'
|
33
35
|
|
34
36
|
spec.add_development_dependency "bundler", "~> 1.13"
|
35
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_cop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Clopton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: harvested
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|