goal 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e6dc9f385d0532851d70b7d1d37a24cb250709f
4
- data.tar.gz: 636a43dc39b232239589589602b3691f9b23ccf8
3
+ metadata.gz: 8d56f5e9e0c22d0b08781b9dbdf216e984a6d1a8
4
+ data.tar.gz: bd8b68ca175fff89f194f74d918aa73d4d9dc50d
5
5
  SHA512:
6
- metadata.gz: 16be09eaf6287db18b6fa0e3aee7e25142b4e705baabbbc733a362e16a8ac4eab8018682637c103d449793b381364ecd0f5442e2e539d88d93ceb25197bc4b22
7
- data.tar.gz: 1880eda0ab7fb3e59fd0969ed4ccc30223f725381edac0143fff21c867c8b478d85268da348e68c535ed74f1738780878578ae11135c296b142b1314397c617c
6
+ metadata.gz: 8a958a934fcbf74fdb4ba7dc3d99ca9209f412a62cde80d10eff55f72ab8df457a9c27fe686009a7d733f943ed188a0309190dbde96b03b86bfefca57471d446
7
+ data.tar.gz: 1dcc996014c566cbf6bdc477457128b5ac6bbfd555e648aaa2e1f30d6e479b7af4a0d68b5c002b9e4b4ae17cc3dcf6ddf21e4f79f021b39838267526d7f6e3f1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- goal (0.1.0)
4
+ goal (0.3.0)
5
5
  colorize (~> 0.6.0)
6
6
  ruby-freshbooks (~> 0.4.1)
7
7
 
data/bin/goal CHANGED
@@ -16,6 +16,10 @@ optparse = OptionParser.new do |opts|
16
16
  options[:token] = t
17
17
  end
18
18
 
19
+ opts.on("-p", "--project=PROJECT", "Freshbooks project id") do |p|
20
+ options[:project_id] = p.to_i
21
+ end
22
+
19
23
  opts.on("-g", "--goals=[GOALS]", "Your goal list. Ex 160:200:300") do |g|
20
24
  options[:goal_list] = g.split(':').map(&:to_i)
21
25
  end
@@ -27,11 +31,15 @@ optparse = OptionParser.new do |opts|
27
31
  opts.on("-m", "--money=MONEY", "The money rate.") do |m|
28
32
  options[:money_rate] = m.to_f
29
33
  end
34
+
35
+ opts.on("-d", "--start_day=START_DAY", "Start day.") do |s|
36
+ options[:start_day] = s.to_i
37
+ end
30
38
  end
31
39
 
32
40
  optparse.parse!
33
41
 
34
- unless options[:hours] || (options[:username] && options[:token])
42
+ unless options[:hours] || (options[:username] && options[:token] && options[:project_id])
35
43
  puts 'Arguments -h or -u and -t are required.'
36
44
  puts optparse
37
45
  exit
@@ -5,18 +5,20 @@ require 'goal/report'
5
5
  module Goal
6
6
  class Calculator
7
7
  def initialize(options = {})
8
- @calculator = Goal::HourCalculator.new
9
- @goal_list = options.fetch(:goal_list, [160, 200, 250, 300])
10
- @username = options[:username]
11
- @token = options[:token]
12
- @hours = options[:hours]
8
+ @goal_list = options.fetch(:goal_list, [160, 200, 250, 300])
9
+ @username = options[:username]
10
+ @token = options[:token]
11
+ @project_id = options[:project_id]
12
+ @hours = options[:hours]
13
13
  @money_rate = options[:money_rate]
14
+ @start_day = options.fetch(:start_day, 1)
15
+ @calculator = Goal::HourCalculator.new(start_day)
14
16
  end
15
17
 
16
18
  def worked_time
17
- if hours
19
+ @time ||= if hours
18
20
  hours
19
- elsif username && token
21
+ elsif username && token && project_id
20
22
  freshbooks.hours
21
23
  else
22
24
  0
@@ -44,10 +46,10 @@ module Goal
44
46
  private
45
47
 
46
48
  attr_reader :base, :calculator, :goal_list, :username, :token, :hours,
47
- :money_rate
49
+ :money_rate, :start_day, :project_id
48
50
 
49
51
  def freshbooks
50
- Goal::FreshbooksCalculator.new(username, token)
52
+ Goal::FreshbooksCalculator.new(username, token, project_id, start_day)
51
53
  end
52
54
 
53
55
  def goals
@@ -2,9 +2,11 @@ require 'ruby-freshbooks'
2
2
 
3
3
  module Goal
4
4
  class FreshbooksCalculator
5
- def initialize(freshbooks_username, token)
6
- @username = freshbooks_username
7
- @token = token
5
+ def initialize(freshbooks_username, token, project_id, start_day)
6
+ @username = freshbooks_username
7
+ @token = token
8
+ @project_id = project_id
9
+ @start_day = start_day
8
10
  end
9
11
 
10
12
  def hours
@@ -13,24 +15,28 @@ module Goal
13
15
 
14
16
  private
15
17
 
16
- attr_reader :username, :token
18
+ attr_reader :username, :token, :start_day, :project_id
17
19
 
18
20
  def entries_for_month
19
- entries = connection.time_entry.list(date_from: date_from, date_to: date_to, per_page: per_page)
20
-
21
- if entries.has_key?('time_entries')
22
- entries['time_entries']['time_entry']
21
+ entries = connection.time_entry.list(date_from: date_from, date_to: date_to, project_id: project_id, per_page: per_page)
22
+
23
+ if entries.has_key?('time_entries') &&entries['time_entries'].has_key?('time_entry')
24
+ if entries['time_entries']['time_entry'].is_a?(Array)
25
+ entries['time_entries']['time_entry']
26
+ else
27
+ [] << entries['time_entries']['time_entry']
28
+ end
23
29
  else
24
30
  []
25
31
  end
26
32
  end
27
33
 
28
34
  def date_from
29
- Date.new Date.today.year, Date.today.month, 1
35
+ Date.new Date.today.year, Date.today.month, start_day
30
36
  end
31
37
 
32
38
  def date_to
33
- Date.new Date.today.year, Date.today.month, -1
39
+ date_from + 30
34
40
  end
35
41
 
36
42
  def per_page
@@ -1,10 +1,14 @@
1
1
  module Goal
2
2
  class HourCalculator
3
+ def initialize(start_day)
4
+ @start_day = start_day
5
+ end
6
+
3
7
  def total_days_until(date = Date.today)
4
8
  total = 0
5
9
  month = Date.today.month
6
10
  year = Date.today.year
7
- date.day.downto(1) do |day|
11
+ date.day.downto(start_day) do |day|
8
12
  current = Date.new(year, month, day)
9
13
 
10
14
  total += 1 unless current.saturday? || current.sunday?
@@ -15,7 +19,7 @@ module Goal
15
19
 
16
20
  def estimated_for(goal)
17
21
  current_days = total_days_until
18
- total_days = total_days_until(end_of_month)
22
+ total_days = total_days_until(end_of_period)
19
23
 
20
24
  hours_per_day = goal.to_f / total_days.to_f
21
25
 
@@ -31,13 +35,15 @@ module Goal
31
35
  end
32
36
 
33
37
  def days_left
34
- total_days_until(end_of_month) - total_days_until + 1
38
+ total_days_until(end_of_period) - total_days_until + 1
35
39
  end
36
40
 
37
41
  private
38
42
 
39
- def end_of_month
40
- Date.new(Date.today.year, Date.today.month, -1)
43
+ attr_reader :start_day
44
+
45
+ def end_of_period
46
+ Date.new(Date.today.year, Date.today.month, start_day) + 30
41
47
  end
42
48
  end
43
49
  end
@@ -1,3 +1,3 @@
1
1
  module Goal
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'
3
3
  end
@@ -14,13 +14,13 @@ describe Goal::Calculator do
14
14
 
15
15
  context 'with hours' do
16
16
  subject do
17
- described_class.new(username: 'username', token: 'token')
17
+ described_class.new(username: 'username', token: 'token', project_id: 222)
18
18
  end
19
19
 
20
20
  it 'should return the freshbooks hours' do
21
21
  instance = double(:instance)
22
22
 
23
- Goal::FreshbooksCalculator.should_receive(:new).with('username', 'token').and_return(instance)
23
+ Goal::FreshbooksCalculator.should_receive(:new).with('username', 'token', 222, 1).and_return(instance)
24
24
  instance.should_receive(:hours).and_return 55.55
25
25
 
26
26
  expect(subject.worked_time).to eq 55.55
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe Goal::FreshbooksCalculator do
4
4
  let(:time_entry) { double(:time_entry) }
5
5
  let(:connection) { double(:connection, time_entry: time_entry) }
6
- let(:end_of_month) { Date.new Date.today.year, Date.today.month, -1 }
7
- let(:begin_of_month) { Date.new Date.today.year, Date.today.month, 1 }
6
+ let(:begin_of_month) { Date.new Date.today.year, Date.today.month, 5 }
8
7
 
9
8
  let :entries do
10
9
  {
@@ -29,7 +28,7 @@ describe Goal::FreshbooksCalculator do
29
28
  end
30
29
 
31
30
  subject do
32
- described_class.new 'username', 'token'
31
+ described_class.new 'username', 'token', 12, 5
33
32
  end
34
33
 
35
34
  describe '#hours' do
@@ -38,7 +37,7 @@ describe Goal::FreshbooksCalculator do
38
37
  FreshBooks::Client.should_receive(:new).with('username.freshbooks.com', 'token').and_return(connection)
39
38
  time_entry.
40
39
  should_receive(:list).
41
- with(date_from: begin_of_month, date_to: end_of_month, per_page: 1000).
40
+ with(date_from: begin_of_month, date_to: begin_of_month + 30, project_id: 12, per_page: 1000).
42
41
  and_return(entries)
43
42
 
44
43
  expect(subject.hours).to eq 15.9
@@ -50,7 +49,7 @@ describe Goal::FreshbooksCalculator do
50
49
  FreshBooks::Client.should_receive(:new).with('username.freshbooks.com', 'token').and_return(connection)
51
50
  time_entry.
52
51
  should_receive(:list).
53
- with(date_from: begin_of_month, date_to: end_of_month, per_page: 1000).
52
+ with(date_from: begin_of_month, date_to: begin_of_month + 30, project_id: 12, per_page: 1000).
54
53
  and_return(error_entries)
55
54
 
56
55
  expect(subject.hours).to eq 0
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Goal::HourCalculator do
4
+ subject do
5
+ described_class.new(1)
6
+ end
7
+
4
8
  describe '#total_days_until' do
5
9
  it 'should calculate the business days from the beginning of the month until the specified day' do
6
10
  Date.stub(today: Date.new(2013, 10, 1))
@@ -52,7 +52,7 @@ describe Goal::Report do
52
52
  report += "| 200 | 121.74 | 12.22 |\n"
53
53
  report += "|--------------------------------|\n"
54
54
  report += "| Current time: 90.0\n"
55
- report += "| Current money: 15000.45\n"
55
+ report += "| Current money: 15.000,45\n"
56
56
  report += "| Current rate: 6.43\n"
57
57
  report += "| Days left: 9"
58
58
 
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.2.0
4
+ version: 0.3.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-11 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-freshbooks
@@ -112,8 +112,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.1.9
115
+ rubygems_version: 2.1.11
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Keep track of your hour goals
119
119
  test_files: []
120
+ has_rdoc: