beggar 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,5 @@
1
1
  rvm:
2
- - 1.9.2
3
2
  - 1.9.3
4
- - ruby-head
5
3
  script: bundle exec rspec spec
6
4
  notifications:
7
5
  email:
@@ -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
- httparty (0.8.1)
12
- multi_json
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
- multi_json (1.1.0)
15
- multi_xml (0.4.1)
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
- Weekdays: 78%
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>
@@ -22,4 +22,6 @@ Gem::Specification.new do |s|
22
22
  # specify any dependencies here; for example:
23
23
  s.add_development_dependency "rspec", ">= 2.7.0"
24
24
  s.add_dependency "httparty"
25
+ s.add_dependency "mechanize"
26
+ s.add_dependency "holidays"
25
27
  end
@@ -8,7 +8,7 @@ module Beggar
8
8
  end
9
9
 
10
10
  def progress
11
- "#{CurrentMonth.weekdays_progression}%"
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
- Weekdays: #{progress}
24
+ Workdays: #{progress}
25
25
  Worked hours: #{worked_hours}
26
26
  Salary: #{salary}}
27
27
  end
@@ -20,12 +20,12 @@ module Beggar
20
20
  @current_user ||= self.class.get('/me.xml')['person']['id']
21
21
  end
22
22
 
23
- def current_month
24
- @current_month ||= time_report(from: CurrentMonth.first_day, to: CurrentMonth.today)
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 = current_month['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
- CurrentMonth.weekday_hours_until_today - worked_hours
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
@@ -31,7 +31,8 @@ module Beggar
31
31
  {
32
32
  "company" => "___",
33
33
  "token" => "___",
34
- "rate" => "___"
34
+ "rate" => "___",
35
+ "country" => "___"
35
36
  }
36
37
  end
37
38
 
@@ -1,49 +1,54 @@
1
+ require 'holidays'
2
+
1
3
  module Beggar
2
4
  class CurrentMonth
3
- class << self
4
- def weekdays
5
- weekdays_until(last_day)
6
- end
7
-
8
- def weekdays_until_today
9
- weekdays_until(today)
10
- end
11
-
12
- def weekday_hours
13
- weekdays * 8.0
14
- end
15
-
16
- def weekday_hours_until_today
17
- weekdays_until_today * 8.0
18
- end
19
-
20
- def weekdays_progression
21
- (weekdays_until_today * 100.0 / weekdays).round
22
- end
23
-
24
- def weekdays_until(date)
25
- (first_day..date).reject { |d| [0, 6].include? d.wday }.length
26
- end
27
-
28
- def first_day
29
- Date.new(year, month, 1)
30
- end
31
-
32
- def last_day
33
- first_day.next_month - 1
34
- end
35
-
36
- def year
37
- today.year
38
- end
39
-
40
- def month
41
- today.month
42
- end
43
-
44
- def today
45
- Date.today
46
- end
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
@@ -1,4 +1,4 @@
1
1
  module Beggar
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.4"
3
3
  end
4
4
 
@@ -2,7 +2,8 @@
2
2
  require 'beggar'
3
3
 
4
4
  describe Beggar::Base do
5
- let(:basecamp) { double('Basecamp', config: { 'rate' => 50.0 }) }
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 9% on 2nd December 2011' do
15
+ it 'returns 10% on 2nd December 2011' do
15
16
  Date.stub(today: Date.new(2011, 12, 2))
16
- base.progress.should == "9%"
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
- Weekdays: 78%
69
+ Workdays: 78%
69
70
  Worked hours: 140.0h (-12.0h)
70
71
  Salary: 5320.0zł (-456.0zł)}
71
72
  end
@@ -43,29 +43,29 @@ describe Beggar::Basecamp do
43
43
  to: Date.new(2012, 02,17)
44
44
  }
45
45
  )
46
- basecamp.current_month
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(current_month: response)
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(current_month: response)
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 > weekdays hours' do
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 < weekdays hours' do
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
@@ -28,7 +28,8 @@ describe Beggar::CLI do
28
28
  {
29
29
  "company" => "___",
30
30
  "token" => "___",
31
- "rate" => "___"
31
+ "rate" => "___",
32
+ "country" => "___"
32
33
  }
33
34
  }
34
35
 
@@ -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 weekdays' do
11
- current_month.weekdays.should == 21
10
+ it 'returns workdays' do
11
+ current_month.workdays.should == 21
12
12
  end
13
13
 
14
- it 'returns weekdays until today' do
15
- current_month.weekdays_until_today.should == 13
14
+ it 'returns workdays until today' do
15
+ current_month.workdays_until_today.should == 13
16
16
  end
17
17
 
18
- it 'returns weekdays in hours' do
19
- current_month.weekday_hours.should == 168.0
18
+ it 'returns workdays in hours' do
19
+ current_month.workday_hours.should == 168.0
20
20
  end
21
21
 
22
- it 'returns weekdays in hours until today' do
23
- current_month.weekday_hours_until_today.should == 104.0
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 weekdays progression' do
27
- current_month.weekdays_progression.should == 62
26
+ it 'returns workdays progression' do
27
+ current_month.workdays_progression.should == 62
28
28
  end
29
29
 
30
- it 'returns weekdays until date' do
30
+ it 'returns workdays until date' do
31
31
  date = Date.new(2012, 2, 23)
32
- current_month.weekdays_until(date).should == 17
32
+ current_month.workdays_until(date).should == 17
33
33
  end
34
34
 
35
35
  it 'returns first day of month' do
@@ -1,4 +1,4 @@
1
1
  company: pear
2
2
  token: abc123
3
3
  rate: 50.0
4
-
4
+ country: pl
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.2
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-03-03 00:00:00.000000000 Z
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: &70354965969800 !ruby/object:Gem::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: *70354965969800
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: &70354965969380 !ruby/object:Gem::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: *70354965969380
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.11
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