Class: HarvestOvertime

Inherits:
Object
  • Object
show all
Defined in:
lib/harvest_overtime.rb

Constant Summary collapse

HOURS_PER_DAY =
8

Instance Method Summary collapse

Constructor Details

#initialize(account_id: nil, personal_access_token: nil, harvest_client: nil, business_days_computer: nil) ⇒ HarvestOvertime

Returns a new instance of HarvestOvertime.



12
13
14
15
# File 'lib/harvest_overtime.rb', line 12

def initialize(account_id: nil, personal_access_token: nil, harvest_client: nil, business_days_computer: nil)
  @business_days_computer = business_days_computer || BusinessDaysComputer.new
  @harvest_client = harvest_client || build_default_harvest_client(, personal_access_token)
end

Instance Method Details

#monthly_stats(start_date, end_date) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/harvest_overtime.rb', line 17

def monthly_stats(start_date, end_date)
  business_days = business_days_computer.business_days(start_date, end_date)
  business_hours_number_by_month = compute_per_month_business_hours_number(business_days)

  time_entries = harvest_client.time_entries(start_date, end_date)
  billed_hours_by_month = sum_billed_hours_by_month(time_entries)

  business_hours_number_by_month.each_with_object({}) do |(month, business_hours), hash|
    billed_hours = billed_hours_by_month[month] || 0

    hash[month] = TimeStats.new(business_hours, billed_hours)
  end
end