goal 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +25 -5
- data/bin/goal +4 -0
- data/lib/goal/hour_calculator.rb +1 -1
- data/lib/goal/report.rb +19 -4
- data/lib/goal/version.rb +1 -1
- data/lib/goal.rb +12 -2
- data/spec/calculator_spec.rb +3 -3
- data/spec/hour_calculator_spec.rb +57 -4
- data/spec/report_spec.rb +30 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6dc9f385d0532851d70b7d1d37a24cb250709f
|
4
|
+
data.tar.gz: 636a43dc39b232239589589602b3691f9b23ccf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16be09eaf6287db18b6fa0e3aee7e25142b4e705baabbbc733a362e16a8ac4eab8018682637c103d449793b381364ecd0f5442e2e539d88d93ceb25197bc4b22
|
7
|
+
data.tar.gz: 1880eda0ab7fb3e59fd0969ed4ccc30223f725381edac0143fff21c867c8b478d85268da348e68c535ed74f1738780878578ae11135c296b142b1314397c617c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/goal.png)](http://badge.fury.io/rb/goal)
|
2
|
+
|
1
3
|
Goal
|
2
4
|
====
|
3
5
|
|
@@ -27,9 +29,9 @@ $ goal -u freshbooks_user -t freshbooks_token
|
|
27
29
|
| 250 | 152 | 14.93 |
|
28
30
|
| 300 | 182 | 20.48 |
|
29
31
|
|____________________________|
|
30
|
-
| Current:
|
31
|
-
|
|
32
|
-
| Days left:
|
32
|
+
| Current time: 115.66h
|
33
|
+
| Current rate: 8.26h
|
34
|
+
| Days left: 9
|
33
35
|
```
|
34
36
|
|
35
37
|
or
|
@@ -43,8 +45,25 @@ $ goal -h 115.66
|
|
43
45
|
| 250 | 152 | 14.93 |
|
44
46
|
| 300 | 182 | 20.48 |
|
45
47
|
|____________________________|
|
46
|
-
| Current:
|
47
|
-
|
|
48
|
+
| Current time: 115.66h
|
49
|
+
| Current rate: 8.26h
|
50
|
+
| Days left: 9
|
51
|
+
```
|
52
|
+
|
53
|
+
or
|
54
|
+
|
55
|
+
```bash
|
56
|
+
$ goal -h 115.66 -m 120
|
57
|
+
|
58
|
+
| Goals | Expected | Average |
|
59
|
+
| 160 | 97 | 4.93 |
|
60
|
+
| 200 | 121 | 9.37 |
|
61
|
+
| 250 | 152 | 14.93 |
|
62
|
+
| 300 | 182 | 20.48 |
|
63
|
+
|____________________________|
|
64
|
+
| Current time: 115.66h
|
65
|
+
| Current money: 13.879.20
|
66
|
+
| Current rate: 8.26h
|
48
67
|
| Days left: 9
|
49
68
|
```
|
50
69
|
|
@@ -56,6 +75,7 @@ Usage: goal [options]
|
|
56
75
|
-t, --token=TOKEN Freshbooks token
|
57
76
|
-g, --goals=[GOALS] Your goal list. Ex 160:200:300
|
58
77
|
-h, --hours=HOURS Worked time in hours.
|
78
|
+
-m, --money=MONEY The money rate.
|
59
79
|
```
|
60
80
|
|
61
81
|
Options `-u` and `-t` are required and specify the user and token to access the
|
data/bin/goal
CHANGED
@@ -23,6 +23,10 @@ optparse = OptionParser.new do |opts|
|
|
23
23
|
opts.on("-h", "--hours=HOURS", "Worked time in hours.") do |h|
|
24
24
|
options[:hours] = h.to_f
|
25
25
|
end
|
26
|
+
|
27
|
+
opts.on("-m", "--money=MONEY", "The money rate.") do |m|
|
28
|
+
options[:money_rate] = m.to_f
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
optparse.parse!
|
data/lib/goal/hour_calculator.rb
CHANGED
data/lib/goal/report.rb
CHANGED
@@ -26,10 +26,17 @@ module Goal
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def footer
|
29
|
-
"|" + ('-' * ((column_width * 3) + 8)) + "|\n"
|
30
|
-
"| Current time:
|
31
|
-
|
32
|
-
|
29
|
+
summary = "|" + ('-' * ((column_width * 3) + 8)) + "|\n"
|
30
|
+
summary += "| Current time: #{data[:summary][:total_time]}\n"
|
31
|
+
|
32
|
+
if data[:summary][:money]
|
33
|
+
summary += "| Current money: #{number_to_currency(data[:summary][:money])}\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
summary += "| Current rate: #{data[:summary][:rate]}\n"
|
37
|
+
summary += "| Days left: #{data[:summary][:days_left]}"
|
38
|
+
|
39
|
+
summary
|
33
40
|
end
|
34
41
|
|
35
42
|
def row(columns)
|
@@ -43,5 +50,13 @@ module Goal
|
|
43
50
|
c.to_s.ljust(column_width)
|
44
51
|
end
|
45
52
|
end
|
53
|
+
|
54
|
+
def number_to_currency(value)
|
55
|
+
val_str = ("%.2f" % [value.to_s]).gsub('.', ',')
|
56
|
+
|
57
|
+
while val_str.sub!(/(\d+)(\d\d\d)/, '\1.\2'); end
|
58
|
+
|
59
|
+
val_str
|
60
|
+
end
|
46
61
|
end
|
47
62
|
end
|
data/lib/goal/version.rb
CHANGED
data/lib/goal.rb
CHANGED
@@ -10,6 +10,7 @@ module Goal
|
|
10
10
|
@username = options[:username]
|
11
11
|
@token = options[:token]
|
12
12
|
@hours = options[:hours]
|
13
|
+
@money_rate = options[:money_rate]
|
13
14
|
end
|
14
15
|
|
15
16
|
def worked_time
|
@@ -22,6 +23,10 @@ module Goal
|
|
22
23
|
end.round(2)
|
23
24
|
end
|
24
25
|
|
26
|
+
def total_money
|
27
|
+
(worked_time * money_rate).round(2)
|
28
|
+
end
|
29
|
+
|
25
30
|
# It calculates the current hour rate
|
26
31
|
def rate
|
27
32
|
calculator.hour_rate(worked_time).round(2)
|
@@ -38,7 +43,8 @@ module Goal
|
|
38
43
|
|
39
44
|
private
|
40
45
|
|
41
|
-
attr_reader :base, :calculator, :goal_list, :username, :token, :hours
|
46
|
+
attr_reader :base, :calculator, :goal_list, :username, :token, :hours,
|
47
|
+
:money_rate
|
42
48
|
|
43
49
|
def freshbooks
|
44
50
|
Goal::FreshbooksCalculator.new(username, token)
|
@@ -59,11 +65,15 @@ module Goal
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def summary
|
62
|
-
{
|
68
|
+
data = {
|
63
69
|
total_time: worked_time,
|
64
70
|
rate: rate,
|
65
71
|
days_left: calculator.days_left
|
66
72
|
}
|
73
|
+
|
74
|
+
data[:money] = total_money if money_rate
|
75
|
+
|
76
|
+
data
|
67
77
|
end
|
68
78
|
end
|
69
79
|
end
|
data/spec/calculator_spec.rb
CHANGED
@@ -53,18 +53,18 @@ describe Goal::Calculator do
|
|
53
53
|
{
|
54
54
|
goal: 160,
|
55
55
|
expected: 97.39,
|
56
|
-
average: 7.
|
56
|
+
average: 7.0
|
57
57
|
},
|
58
58
|
{
|
59
59
|
goal: 200,
|
60
60
|
expected: 121.74,
|
61
|
-
average:
|
61
|
+
average: 11.0
|
62
62
|
}
|
63
63
|
],
|
64
64
|
summary: {
|
65
65
|
total_time: 90.0,
|
66
66
|
rate: 6.43,
|
67
|
-
days_left:
|
67
|
+
days_left: 10
|
68
68
|
}
|
69
69
|
})
|
70
70
|
end
|
@@ -3,6 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe Goal::HourCalculator do
|
4
4
|
describe '#total_days_until' do
|
5
5
|
it 'should calculate the business days from the beginning of the month until the specified day' do
|
6
|
+
Date.stub(today: Date.new(2013, 10, 1))
|
7
|
+
|
6
8
|
expect(subject.total_days_until Date.new(2013, 10, 17)).to eq 13 # Thursday
|
7
9
|
expect(subject.total_days_until Date.new(2013, 10, 18)).to eq 14 # Friday
|
8
10
|
expect(subject.total_days_until Date.new(2013, 10, 19)).to eq 14 # Saturday
|
@@ -32,21 +34,72 @@ describe Goal::HourCalculator do
|
|
32
34
|
|
33
35
|
expect(subject.hour_rate(95)).to eq 6.785714285714286
|
34
36
|
end
|
37
|
+
|
38
|
+
context 'when on the last day of the month' do
|
39
|
+
it 'should calculate the hour rate' do
|
40
|
+
Date.stub(today: Date.new(2013, 10, 31))
|
41
|
+
|
42
|
+
expect(subject.hour_rate(200)).to eq 8.695652173913043
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when on the first day of the month' do
|
47
|
+
it 'should calculate the hour rate' do
|
48
|
+
Date.stub(today: Date.new(2013, 10, 1))
|
49
|
+
|
50
|
+
expect(subject.hour_rate(0)).to eq 0.0
|
51
|
+
expect(subject.hour_rate(5)).to eq 5.0
|
52
|
+
end
|
53
|
+
end
|
35
54
|
end
|
36
55
|
|
37
56
|
describe '#rate_to_goal' do
|
38
57
|
it 'should calculate the hour per day needed to the goal from the left days of the month' do
|
39
58
|
Date.stub(today: Date.new(2013, 10, 18))
|
40
59
|
|
41
|
-
expect(subject.rate_to_goal(200, 115.66)).to eq
|
60
|
+
expect(subject.rate_to_goal(200, 115.66)).to eq 8.434000000000001
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when on the last day of the month' do
|
64
|
+
it 'should calculate rate_to_goal' do
|
65
|
+
Date.stub(today: Date.new(2013, 10, 31))
|
66
|
+
|
67
|
+
expect(subject.rate_to_goal(200, 115.66)).to eq 84.34
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when on the first day of the month' do
|
72
|
+
it 'should calculate the rate to goal' do
|
73
|
+
Date.stub(today: Date.new(2013, 10, 1))
|
74
|
+
|
75
|
+
expect(subject.rate_to_goal(200, 0)).to eq 8.0
|
76
|
+
end
|
42
77
|
end
|
43
78
|
end
|
44
79
|
|
45
80
|
describe '#days_left' do
|
46
|
-
|
47
|
-
|
81
|
+
context 'when in beginning of the month' do
|
82
|
+
it 'should return the days left from de month since today' do
|
83
|
+
Date.stub(today: Date.new(2013, 10, 1))
|
84
|
+
|
85
|
+
expect(subject.days_left).to eq 23
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when in middle of the month' do
|
90
|
+
it 'should return the days left from de month since today' do
|
91
|
+
Date.stub(today: Date.new(2013, 10, 18))
|
92
|
+
|
93
|
+
expect(subject.days_left).to eq 10
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when in the end of the month' do
|
98
|
+
it 'should return the days left from de month since today' do
|
99
|
+
Date.stub(today: Date.new(2013, 10, 31))
|
48
100
|
|
49
|
-
|
101
|
+
expect(subject.days_left).to eq 1
|
102
|
+
end
|
50
103
|
end
|
51
104
|
end
|
52
105
|
end
|
data/spec/report_spec.rb
CHANGED
@@ -23,21 +23,41 @@ describe Goal::Report do
|
|
23
23
|
}
|
24
24
|
end
|
25
25
|
|
26
|
+
|
26
27
|
subject do
|
27
28
|
described_class.new(data)
|
28
29
|
end
|
29
30
|
|
30
31
|
describe '#to_s' do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
context 'when has not money setted to summary' do
|
33
|
+
it 'should build the report' do
|
34
|
+
report = "| Goals | Expected | Average |\n"
|
35
|
+
report += "| 160 | 97.39 | 7.78 |\n"
|
36
|
+
report += "| 200 | 121.74 | 12.22 |\n"
|
37
|
+
report += "|--------------------------------|\n"
|
38
|
+
report += "| Current time: 90.0\n"
|
39
|
+
report += "| Current rate: 6.43\n"
|
40
|
+
report += "| Days left: 9"
|
41
|
+
|
42
|
+
expect(subject.to_s).to eq report
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when has money setted to summary' do
|
47
|
+
it 'should build the report' do
|
48
|
+
data[:summary][:money] = 15000.45
|
49
|
+
|
50
|
+
report = "| Goals | Expected | Average |\n"
|
51
|
+
report += "| 160 | 97.39 | 7.78 |\n"
|
52
|
+
report += "| 200 | 121.74 | 12.22 |\n"
|
53
|
+
report += "|--------------------------------|\n"
|
54
|
+
report += "| Current time: 90.0\n"
|
55
|
+
report += "| Current money: 15000.45\n"
|
56
|
+
report += "| Current rate: 6.43\n"
|
57
|
+
report += "| Days left: 9"
|
58
|
+
|
59
|
+
expect(subject.to_s).to eq report
|
60
|
+
end
|
41
61
|
end
|
42
62
|
end
|
43
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateus Lorandi dos Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-freshbooks
|