beggar 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -2
- data/Gemfile.lock +26 -4
- data/README.md +16 -3
- data/beggar.gemspec +2 -0
- data/lib/beggar/base.rb +2 -2
- data/lib/beggar/basecamp.rb +12 -4
- data/lib/beggar/cli.rb +2 -1
- data/lib/beggar/current_month.rb +49 -44
- data/lib/beggar/version.rb +1 -1
- data/spec/base_spec.rb +5 -4
- data/spec/basecamp_spec.rb +5 -5
- data/spec/cli_spec.rb +2 -1
- data/spec/current_month_spec.rb +13 -13
- data/spec/fixtures/beggar +1 -1
- metadata +49 -7
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,17 +2,35 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
beggar (1.0.2)
|
5
|
+
holidays
|
5
6
|
httparty
|
7
|
+
mechanize
|
6
8
|
|
7
9
|
GEM
|
8
10
|
remote: http://rubygems.org/
|
9
11
|
specs:
|
10
12
|
diff-lcs (1.1.3)
|
11
|
-
|
12
|
-
|
13
|
+
domain_name (0.5.6)
|
14
|
+
unf (~> 0.0.3)
|
15
|
+
holidays (1.0.5)
|
16
|
+
httparty (0.9.0)
|
17
|
+
multi_json (~> 1.0)
|
13
18
|
multi_xml
|
14
|
-
|
15
|
-
|
19
|
+
mechanize (2.5.1)
|
20
|
+
domain_name (~> 0.5, >= 0.5.1)
|
21
|
+
mime-types (~> 1.17, >= 1.17.2)
|
22
|
+
net-http-digest_auth (~> 1.1, >= 1.1.1)
|
23
|
+
net-http-persistent (~> 2.5, >= 2.5.2)
|
24
|
+
nokogiri (~> 1.4)
|
25
|
+
ntlm-http (~> 0.1, >= 0.1.1)
|
26
|
+
webrobots (~> 0.0, >= 0.0.9)
|
27
|
+
mime-types (1.19)
|
28
|
+
multi_json (1.5.0)
|
29
|
+
multi_xml (0.5.1)
|
30
|
+
net-http-digest_auth (1.2.1)
|
31
|
+
net-http-persistent (2.8)
|
32
|
+
nokogiri (1.5.6)
|
33
|
+
ntlm-http (0.1.1)
|
16
34
|
rspec (2.8.0)
|
17
35
|
rspec-core (~> 2.8.0)
|
18
36
|
rspec-expectations (~> 2.8.0)
|
@@ -21,6 +39,10 @@ GEM
|
|
21
39
|
rspec-expectations (2.8.0)
|
22
40
|
diff-lcs (~> 1.1.2)
|
23
41
|
rspec-mocks (2.8.0)
|
42
|
+
unf (0.0.5)
|
43
|
+
unf_ext
|
44
|
+
unf_ext (0.0.5)
|
45
|
+
webrobots (0.0.13)
|
24
46
|
|
25
47
|
PLATFORMS
|
26
48
|
ruby
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Beggar is a tool for generating time reports from your Basecamp account
|
|
7
7
|
Example output:
|
8
8
|
|
9
9
|
Current month
|
10
|
-
|
10
|
+
Workdays: 78%
|
11
11
|
Worked hours: 140.0h (-12.0h)
|
12
12
|
Salary: 5320.0zł (-456.0zł)
|
13
13
|
|
@@ -30,8 +30,21 @@ Example config:
|
|
30
30
|
company: pear
|
31
31
|
token: abc123
|
32
32
|
rate: 50.0
|
33
|
+
country: pl
|
33
34
|
|
34
35
|
## Changelog
|
35
|
-
v1.0.1 - change output
|
36
|
-
v1.0.0 - first stable release
|
37
36
|
|
37
|
+
<table>
|
38
|
+
<tr>
|
39
|
+
<td>v1.0.3</td><td>don't count holidays as working days</td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<td>v1.0.2</td><td>fix bug when time entries are empty</td>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<td>v1.0.1</td><td>change output</td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td>v1.0.0</td><td>first stable release</td>
|
49
|
+
</tr>
|
50
|
+
</table>
|
data/beggar.gemspec
CHANGED
data/lib/beggar/base.rb
CHANGED
@@ -8,7 +8,7 @@ module Beggar
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def progress
|
11
|
-
"#{
|
11
|
+
"#{basecamp.workdays_progression}%"
|
12
12
|
end
|
13
13
|
|
14
14
|
def worked_hours
|
@@ -21,7 +21,7 @@ module Beggar
|
|
21
21
|
|
22
22
|
def summary
|
23
23
|
%Q{Current month
|
24
|
-
|
24
|
+
Workdays: #{progress}
|
25
25
|
Worked hours: #{worked_hours}
|
26
26
|
Salary: #{salary}}
|
27
27
|
end
|
data/lib/beggar/basecamp.rb
CHANGED
@@ -20,12 +20,12 @@ module Beggar
|
|
20
20
|
@current_user ||= self.class.get('/me.xml')['person']['id']
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@
|
23
|
+
def current_month_report
|
24
|
+
@current_month_report ||= time_report(from: current_month.first_day, to: current_month.today)
|
25
25
|
end
|
26
26
|
|
27
27
|
def worked_hours
|
28
|
-
time_entries =
|
28
|
+
time_entries = current_month_report['time_entries']
|
29
29
|
return 0 if time_entries.empty?
|
30
30
|
time_entries.map do |entry|
|
31
31
|
entry['hours']
|
@@ -33,7 +33,15 @@ module Beggar
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def hours_ratio
|
36
|
-
|
36
|
+
current_month.workday_hours_until_today - worked_hours
|
37
|
+
end
|
38
|
+
|
39
|
+
def workdays_progression
|
40
|
+
current_month.workdays_progression
|
41
|
+
end
|
42
|
+
|
43
|
+
def current_month
|
44
|
+
@current_month ||= CurrentMonth.new(:country => @config['country'])
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
data/lib/beggar/cli.rb
CHANGED
data/lib/beggar/current_month.rb
CHANGED
@@ -1,49 +1,54 @@
|
|
1
|
+
require 'holidays'
|
2
|
+
|
1
3
|
module Beggar
|
2
4
|
class CurrentMonth
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
5
|
+
def initialize(options = {})
|
6
|
+
@country = options[:country]
|
7
|
+
end
|
8
|
+
|
9
|
+
def workdays
|
10
|
+
workdays_until(last_day)
|
11
|
+
end
|
12
|
+
|
13
|
+
def workdays_until_today
|
14
|
+
workdays_until(today)
|
15
|
+
end
|
16
|
+
|
17
|
+
def workday_hours
|
18
|
+
workdays * 8.0
|
19
|
+
end
|
20
|
+
|
21
|
+
def workday_hours_until_today
|
22
|
+
workdays_until_today * 8.0
|
23
|
+
end
|
24
|
+
|
25
|
+
def workdays_progression
|
26
|
+
(workdays_until_today * 100.0 / workdays).round
|
27
|
+
end
|
28
|
+
|
29
|
+
def workdays_until(date)
|
30
|
+
(first_day..date).reject { |d|
|
31
|
+
[0, 6].include?(d.wday) || d.holiday?(@country) }.length
|
32
|
+
end
|
33
|
+
|
34
|
+
def first_day
|
35
|
+
Date.new(year, month, 1)
|
36
|
+
end
|
37
|
+
|
38
|
+
def last_day
|
39
|
+
first_day.next_month - 1
|
40
|
+
end
|
41
|
+
|
42
|
+
def year
|
43
|
+
today.year
|
44
|
+
end
|
45
|
+
|
46
|
+
def month
|
47
|
+
today.month
|
48
|
+
end
|
49
|
+
|
50
|
+
def today
|
51
|
+
Date.today
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
data/lib/beggar/version.rb
CHANGED
data/spec/base_spec.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
require 'beggar'
|
3
3
|
|
4
4
|
describe Beggar::Base do
|
5
|
-
let(:
|
5
|
+
let(:config) { YAML.load_file(File.expand_path('../fixtures/beggar', __FILE__)) }
|
6
|
+
let(:basecamp) { Beggar::Basecamp.new(config) }
|
6
7
|
let(:base) { Beggar::Base.new(basecamp) }
|
7
8
|
|
8
9
|
describe 'displaying weekdays progression as a percents' do
|
@@ -11,9 +12,9 @@ describe Beggar::Base do
|
|
11
12
|
base.progress.should == "62%"
|
12
13
|
end
|
13
14
|
|
14
|
-
it 'returns
|
15
|
+
it 'returns 10% on 2nd December 2011' do
|
15
16
|
Date.stub(today: Date.new(2011, 12, 2))
|
16
|
-
base.progress.should == "
|
17
|
+
base.progress.should == "10%"
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'returns 100% on 30th November 1988' do
|
@@ -65,7 +66,7 @@ describe Beggar::Base do
|
|
65
66
|
it 'returns summary' do
|
66
67
|
base.stub(progress: "78%", worked_hours: "140.0h (-12.0h)", salary: "5320.0zł (-456.0zł)")
|
67
68
|
base.summary.should == %q{Current month
|
68
|
-
|
69
|
+
Workdays: 78%
|
69
70
|
Worked hours: 140.0h (-12.0h)
|
70
71
|
Salary: 5320.0zł (-456.0zł)}
|
71
72
|
end
|
data/spec/basecamp_spec.rb
CHANGED
@@ -43,29 +43,29 @@ describe Beggar::Basecamp do
|
|
43
43
|
to: Date.new(2012, 02,17)
|
44
44
|
}
|
45
45
|
)
|
46
|
-
basecamp.
|
46
|
+
basecamp.current_month_report
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns worked hours' do
|
50
50
|
response = { "time_entries" =>
|
51
51
|
[{ "hours" => 8.0 }, { "hours" => 6.0 }, { "hours" => 8.0 }]
|
52
52
|
}
|
53
|
-
basecamp.stub(
|
53
|
+
basecamp.stub(current_month_report: response)
|
54
54
|
basecamp.worked_hours.should == 22.0
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns 0 when no time entries' do
|
58
58
|
response = { "time_entries" => [] }
|
59
|
-
basecamp.stub(
|
59
|
+
basecamp.stub(current_month_report: response)
|
60
60
|
basecamp.worked_hours.should == 0
|
61
61
|
end
|
62
62
|
|
63
|
-
it 'returns hours ratio with minus when working hours >
|
63
|
+
it 'returns hours ratio with minus when working hours > workdays hours' do
|
64
64
|
basecamp.stub(worked_hours: 106.0)
|
65
65
|
basecamp.hours_ratio.should == -2.0
|
66
66
|
end
|
67
67
|
|
68
|
-
it 'returns hours ratio with plus when worked hours <
|
68
|
+
it 'returns hours ratio with plus when worked hours < workdays hours' do
|
69
69
|
basecamp.stub(worked_hours: 96.0)
|
70
70
|
basecamp.hours_ratio.should == 8.0
|
71
71
|
end
|
data/spec/cli_spec.rb
CHANGED
data/spec/current_month_spec.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'beggar'
|
2
2
|
|
3
3
|
describe Beggar::CurrentMonth do
|
4
|
-
let(:current_month) { Beggar::CurrentMonth }
|
4
|
+
let(:current_month) { Beggar::CurrentMonth.new(:country => 'pl') }
|
5
5
|
|
6
6
|
before do
|
7
7
|
Date.stub(today: Date.new(2012, 2, 17))
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'returns
|
11
|
-
current_month.
|
10
|
+
it 'returns workdays' do
|
11
|
+
current_month.workdays.should == 21
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'returns
|
15
|
-
current_month.
|
14
|
+
it 'returns workdays until today' do
|
15
|
+
current_month.workdays_until_today.should == 13
|
16
16
|
end
|
17
17
|
|
18
|
-
it 'returns
|
19
|
-
current_month.
|
18
|
+
it 'returns workdays in hours' do
|
19
|
+
current_month.workday_hours.should == 168.0
|
20
20
|
end
|
21
21
|
|
22
|
-
it 'returns
|
23
|
-
current_month.
|
22
|
+
it 'returns workdays in hours until today' do
|
23
|
+
current_month.workday_hours_until_today.should == 104.0
|
24
24
|
end
|
25
25
|
|
26
|
-
it 'returns
|
27
|
-
current_month.
|
26
|
+
it 'returns workdays progression' do
|
27
|
+
current_month.workdays_progression.should == 62
|
28
28
|
end
|
29
29
|
|
30
|
-
it 'returns
|
30
|
+
it 'returns workdays until date' do
|
31
31
|
date = Date.new(2012, 2, 23)
|
32
|
-
current_month.
|
32
|
+
current_month.workdays_until(date).should == 17
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'returns first day of month' do
|
data/spec/fixtures/beggar
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beggar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,31 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.7.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: httparty
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mechanize
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
28
49
|
none: false
|
29
50
|
requirements:
|
30
51
|
- - ! '>='
|
@@ -32,7 +53,28 @@ dependencies:
|
|
32
53
|
version: '0'
|
33
54
|
type: :runtime
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: holidays
|
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'
|
36
78
|
description: Tool for generating time reports from Basecamp. You can specify rate
|
37
79
|
for each project and get value of your month salary.
|
38
80
|
email:
|
@@ -83,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
125
|
version: '0'
|
84
126
|
requirements: []
|
85
127
|
rubyforge_project: beggar
|
86
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.23
|
87
129
|
signing_key:
|
88
130
|
specification_version: 3
|
89
131
|
summary: Tool for generating time reports from Basecamp
|