beggar 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beggar (0.0.5.alpha)
4
+ beggar (1.0.0)
5
5
  httparty
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -6,13 +6,10 @@ Beggar is a tool for generating time reports from your Basecamp account
6
6
 
7
7
  Example output:
8
8
 
9
- 78% || 140.0h, -12.0h || 5320.0 zł, -456.0 zł
10
-
11
- where
12
-
13
- 78% - working days progress in current month
14
- 140.0h, -12.0h - worked hours ratio
15
- 5320.0 zł, -456.0 zł - salary ratio
9
+ Current month
10
+ Weekdays: 78%
11
+ Worked hours: 140.0h (-12.0h)
12
+ Salary: 5320.0zł (-456.0zł)
16
13
 
17
14
  ### Installation
18
15
 
@@ -35,5 +32,6 @@ Example config:
35
32
  rate: 50.0
36
33
 
37
34
  ## Changelog
35
+ v1.0.1 - change output
38
36
  v1.0.0 - first stable release
39
37
 
@@ -8,19 +8,22 @@ module Beggar
8
8
  end
9
9
 
10
10
  def progress
11
- "#{CurrentMonth.days_progression}%"
11
+ "#{CurrentMonth.weekdays_progression}%"
12
12
  end
13
13
 
14
14
  def worked_hours
15
- "#{basecamp.worked_hours}h, #{ratio(basecamp.hours_ratio)}h"
15
+ "#{basecamp.worked_hours}h (#{ratio(basecamp.hours_ratio)}h)"
16
16
  end
17
17
 
18
18
  def salary
19
- "#{as_money(basecamp.worked_hours)} zł, #{ratio(as_money(basecamp.hours_ratio))} zł"
19
+ "#{as_money(basecamp.worked_hours)} (#{ratio(as_money(basecamp.hours_ratio))}zł)"
20
20
  end
21
21
 
22
22
  def summary
23
- [progress, worked_hours, salary].join(' || ')
23
+ %Q{Current month
24
+ Weekdays: #{progress}
25
+ Worked hours: #{worked_hours}
26
+ Salary: #{salary}}
24
27
  end
25
28
 
26
29
  private
@@ -12,12 +12,12 @@ module Beggar
12
12
  end
13
13
 
14
14
  def time_report(options = {})
15
- options.merge!( subject_id: current_user )
16
- get(%(/time_entries/report.xml#{params(options)}))
15
+ options.merge!(subject_id: current_user)
16
+ self.class.get("/time_entries/report.xml", :query => options)
17
17
  end
18
18
 
19
19
  def current_user
20
- @current_user ||= get('/me.xml')['person']['id']
20
+ @current_user ||= self.class.get('/me.xml')['person']['id']
21
21
  end
22
22
 
23
23
  def current_month
@@ -33,15 +33,5 @@ module Beggar
33
33
  def hours_ratio
34
34
  CurrentMonth.weekday_hours_until_today - worked_hours
35
35
  end
36
-
37
- private
38
-
39
- def get(path)
40
- self.class.get(path)
41
- end
42
-
43
- def params(options)
44
- '?' + options.map { |name, value| "#{name}=#{value}" }.join('&')
45
- end
46
36
  end
47
37
  end
@@ -2,41 +2,42 @@ module Beggar
2
2
  class CLI
3
3
  class << self
4
4
  def run
5
- begin
5
+ if File.exists?(config)
6
6
  $stdout.puts Base.new(Basecamp.new(load_config)).summary
7
- rescue Errno::ENOENT
7
+ else
8
8
  create_config
9
9
  $stdout.puts "New config has been created in ~/.beggar"
10
10
  $stdout.puts "Please fill it with proper data."
11
- rescue URI::InvalidURIError
12
- $stdout.puts "Ensure that your config file is proper formatted!"
13
11
  end
14
12
  exit 0
13
+ rescue URI::InvalidURIError
14
+ $stdout.puts "Ensure that your config file is proper formatted!"
15
+ exit 1
15
16
  end
16
17
 
17
- private
18
+ private
18
19
 
19
- def load_config
20
- YAML.load_file(config)
21
- end
20
+ def load_config
21
+ YAML.load_file(config)
22
+ end
22
23
 
23
- def create_config
24
- File.open(config, "w") do |output|
25
- YAML.dump(defaults, output)
24
+ def create_config
25
+ File.open(config, "w") do |output|
26
+ YAML.dump(defaults, output)
27
+ end
26
28
  end
27
- end
28
29
 
29
- def defaults
30
- {
31
- "company" => "___",
32
- "token" => "___",
33
- "rate" => "___"
34
- }
35
- end
30
+ def defaults
31
+ {
32
+ "company" => "___",
33
+ "token" => "___",
34
+ "rate" => "___"
35
+ }
36
+ end
36
37
 
37
- def config
38
- "#{Dir.home}/.beggar"
39
- end
38
+ def config
39
+ "#{Dir.home}/.beggar"
40
+ end
40
41
  end
41
42
  end
42
43
  end
@@ -17,7 +17,7 @@ module Beggar
17
17
  weekdays_until_today * 8.0
18
18
  end
19
19
 
20
- def days_progression
20
+ def weekdays_progression
21
21
  (weekdays_until_today * 100.0 / weekdays).round
22
22
  end
23
23
 
@@ -1,4 +1,4 @@
1
1
  module Beggar
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
4
4
 
@@ -27,12 +27,12 @@ describe Beggar::Base do
27
27
  basecamp.stub(worked_hours: 136.0, hours_ratio: 32.0)
28
28
  end
29
29
 
30
- it 'returns "136.0h, -32.0h"' do
31
- base.worked_hours.should == "136.0h, -32.0h"
30
+ it 'returns "136.0h (-32.0h)"' do
31
+ base.worked_hours.should == "136.0h (-32.0h)"
32
32
  end
33
33
 
34
- it 'returns "6800.0 zł, -1600.0 zł"' do
35
- base.salary.should == "6800.0 zł, -1600.0 zł"
34
+ it 'returns "6800.0zł (-1600.0zł)"' do
35
+ base.salary.should == "6800.0zł (-1600.0zł)"
36
36
  end
37
37
  end
38
38
 
@@ -41,12 +41,12 @@ describe Beggar::Base do
41
41
  basecamp.stub(worked_hours: 176.0, hours_ratio: -8.0)
42
42
  end
43
43
 
44
- it 'returns "176.0h, +8.0h"' do
45
- base.worked_hours.should == "176.0h, +8.0h"
44
+ it 'returns "176.0h (+8.0h)"' do
45
+ base.worked_hours.should == "176.0h (+8.0h)"
46
46
  end
47
47
 
48
- it 'returns "8800.0 zł, +$400.0 zł"' do
49
- base.salary.should == "8800.0 zł, +400.0 zł"
48
+ it 'returns "8800.0zł (+$400.0zł)"' do
49
+ base.salary.should == "8800.0zł (+400.0zł)"
50
50
  end
51
51
  end
52
52
 
@@ -63,8 +63,11 @@ describe Beggar::Base do
63
63
  end
64
64
 
65
65
  it 'returns summary' do
66
- base.stub(progress: "78%", worked_hours: "140.0h, -12.0h", salary: "5320.0 zł, -456.0 zł")
67
- base.summary.should == "78% || 140.0h, -12.0h || 5320.0 zł, -456.0 zł"
66
+ base.stub(progress: "78%", worked_hours: "140.0h (-12.0h)", salary: "5320.0zł (-456.0zł)")
67
+ base.summary.should == %q{Current month
68
+ Weekdays: 78%
69
+ Worked hours: 140.0h (-12.0h)
70
+ Salary: 5320.0zł (-456.0zł)}
68
71
  end
69
72
  end
70
73
 
@@ -23,21 +23,26 @@ describe Beggar::Basecamp do
23
23
  end
24
24
 
25
25
  it 'returns user id' do
26
- response = { 'person' => { 'id' => 1 }}
26
+ response = {'person' => { 'id' => 1 }}
27
27
  basecamp.class.should_receive(:get).with('/me.xml').and_return(response)
28
28
  basecamp.current_user.should == 1
29
29
  end
30
30
 
31
31
  it 'returns time report for current user' do
32
32
  basecamp.stub(current_user: 1)
33
- basecamp.class.should_receive(:get).with('/time_entries/report.xml?subject_id=1')
33
+ basecamp.class.should_receive(:get).with('/time_entries/report.xml', query: {subject_id: 1})
34
34
  basecamp.time_report
35
35
  end
36
36
 
37
37
  it 'returns time report for current month' do
38
- Date.stub(today: Date.new(2012, 02, 17))
39
38
  basecamp.stub(current_user: 1)
40
- basecamp.class.should_receive(:get).with('/time_entries/report.xml?from=2012-02-01&to=2012-02-17&subject_id=1')
39
+ basecamp.class.should_receive(:get).with('/time_entries/report.xml',
40
+ query: {
41
+ subject_id: 1,
42
+ from: Date.new(2012, 02, 01),
43
+ to: Date.new(2012, 02,17)
44
+ }
45
+ )
41
46
  basecamp.current_month
42
47
  end
43
48
 
@@ -58,12 +63,4 @@ describe Beggar::Basecamp do
58
63
  basecamp.stub(worked_hours: 96.0)
59
64
  basecamp.hours_ratio.should == 8.0
60
65
  end
61
-
62
- describe 'private methods' do
63
- it 'parses options to path params' do
64
- basecamp.send(:params, { name: 'bob'}).should == '?name=bob'
65
- basecamp.send(:params, { name: 'bob', surname: 'example'}).should == '?name=bob&surname=example'
66
- end
67
- end
68
66
  end
69
-
@@ -14,6 +14,10 @@ describe Beggar::CLI do
14
14
  end
15
15
 
16
16
  context 'when config file exists' do
17
+ before do
18
+ File.stub(:exists?).and_return(true)
19
+ end
20
+
17
21
  it "loads it before running" do
18
22
  YAML.should_receive(:load_file).with(config).and_return(double('configuration'))
19
23
  end
@@ -29,8 +33,9 @@ describe Beggar::CLI do
29
33
  }
30
34
 
31
35
  before do
32
- YAML.should_receive(:load_file).with(config) { raise Errno::ENOENT }
36
+ File.stub(:exists?).and_return(false)
33
37
  end
38
+
34
39
  it "creates config with default settings" do
35
40
  output = double('output')
36
41
  File.should_receive(:open).with(config, "w").and_yield(output)
@@ -44,5 +49,13 @@ describe Beggar::CLI do
44
49
  $stdout.should_receive(:puts).with("Please fill it with proper data.")
45
50
  end
46
51
  end
52
+
53
+ context 'when config file is wrong' do
54
+ it 'displays notification' do
55
+ $stdout.unstub(:puts)
56
+ File.stub(:exists?) { raise URI::InvalidURIError }
57
+ $stdout.should_receive(:puts).with("Ensure that your config file is proper formatted!")
58
+ end
59
+ end
47
60
  end
48
61
 
@@ -1,6 +1,5 @@
1
1
  require 'beggar'
2
2
 
3
- # FIXME add missing specs
4
3
  describe Beggar::CurrentMonth do
5
4
  let(:current_month) { Beggar::CurrentMonth }
6
5
 
@@ -8,6 +7,14 @@ describe Beggar::CurrentMonth do
8
7
  Date.stub(today: Date.new(2012, 2, 17))
9
8
  end
10
9
 
10
+ it 'returns weekdays' do
11
+ current_month.weekdays.should == 21
12
+ end
13
+
14
+ it 'returns weekdays until today' do
15
+ current_month.weekdays_until_today.should == 13
16
+ end
17
+
11
18
  it 'returns weekdays in hours' do
12
19
  current_month.weekday_hours.should == 168.0
13
20
  end
@@ -15,5 +22,34 @@ describe Beggar::CurrentMonth do
15
22
  it 'returns weekdays in hours until today' do
16
23
  current_month.weekday_hours_until_today.should == 104.0
17
24
  end
25
+
26
+ it 'returns weekdays progression' do
27
+ current_month.weekdays_progression.should == 62
28
+ end
29
+
30
+ it 'returns weekdays until date' do
31
+ date = Date.new(2012, 2, 23)
32
+ current_month.weekdays_until(date).should == 17
33
+ end
34
+
35
+ it 'returns first day of month' do
36
+ current_month.first_day.should == Date.new(2012, 2, 1)
37
+ end
38
+
39
+ it 'returns last day of month' do
40
+ current_month.last_day.should == Date.new(2012, 2, 29)
41
+ end
42
+
43
+ it 'returns year' do
44
+ current_month.year.should == 2012
45
+ end
46
+
47
+ it 'returns month' do
48
+ current_month.month.should == 2
49
+ end
50
+
51
+ it 'returns today' do
52
+ current_month.today.should == Date.new(2012, 2, 17)
53
+ end
18
54
  end
19
55
 
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.0
4
+ version: 1.0.1
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-02-18 00:00:00.000000000 Z
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70213892896680 !ruby/object:Gem::Requirement
16
+ requirement: &70364544025140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.7.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70213892896680
24
+ version_requirements: *70364544025140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70213892895980 !ruby/object:Gem::Requirement
27
+ requirement: &70364544023600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70213892895980
35
+ version_requirements: *70364544023600
36
36
  description: Tool for generating time reports from Basecamp. You can specify rate
37
37
  for each project and get value of your month salary.
38
38
  email: