class Goal::HourCalculator

Attributes

start_day[R]

Public Class Methods

new(start_day) click to toggle source
# File lib/goal/hour_calculator.rb, line 3
def initialize(start_day)
  @start_day = start_day
end

Public Instance Methods

days_left() click to toggle source
# File lib/goal/hour_calculator.rb, line 37
def days_left
  total_days_until(end_of_period) - total_days_until + 1
end
estimated_for(goal) click to toggle source
# File lib/goal/hour_calculator.rb, line 20
def estimated_for(goal)
  current_days = total_days_until
  total_days   = total_days_until(end_of_period)

  hours_per_day = goal.to_f / total_days.to_f

  current_days * hours_per_day
end
hour_rate(hours_until_now) click to toggle source
# File lib/goal/hour_calculator.rb, line 29
def hour_rate(hours_until_now)
  hours_until_now.to_f / total_days_until.to_f
end
rate_to_goal(goal, hours_until_now) click to toggle source
# File lib/goal/hour_calculator.rb, line 33
def rate_to_goal(goal, hours_until_now)
  (goal - hours_until_now) / days_left
end
total_days_until(date = Date.today) click to toggle source
# File lib/goal/hour_calculator.rb, line 7
def total_days_until(date = Date.today)
  total = 0
  month = Date.today.month
  year  = Date.today.year
  date.day.downto(start_day) do |day|
    current = Date.new(year, month, day)

    total += 1 unless current.saturday? || current.sunday?
  end

  total
end

Private Instance Methods

end_of_period() click to toggle source
# File lib/goal/hour_calculator.rb, line 45
def end_of_period
  Date.new(Date.today.year, Date.today.month, start_day) + 30
end