module TimeRounder::Schedule::FifteenMinute

Schedule to round on 00, 15, 30, 45

Public Instance Methods

add_hours_array() click to toggle source

Array of minutes that will require an hour be added to the total, because the number return from the partial hours has is .00

# File lib/time_rounder/schedule/fifteen_minute.rb, line 9
def add_hours_array
  [53, 54, 55, 56, 57, 58, 59]
end
closest_to_number(list, number) click to toggle source
# File lib/time_rounder/schedule/fifteen_minute.rb, line 31
def closest_to_number(list, number)
  list.min_by { |x| (x - number).abs }
end
minute_intervals() click to toggle source
# File lib/time_rounder/schedule/fifteen_minute.rb, line 13
def minute_intervals
  [0, 15, 30, 45, 60]
end
minutes_to_closest_partial(minute) click to toggle source

returns the number of minutes to get to the closest partial hour

# File lib/time_rounder/schedule/fifteen_minute.rb, line 27
def minutes_to_closest_partial(minute)
  closest_to_number(minute_intervals, minute)
end
partial_hours_from_minutes(minute) click to toggle source

returns the partial hour total based on what the minute is

# File lib/time_rounder/schedule/fifteen_minute.rb, line 19
def partial_hours_from_minutes(minute)
  partials = { 0 => 0.0, 15 => 0.25, 30 => 0.5, 45 => 0.75, 60 => 0.0 }
  interval = closest_to_number(minute_intervals, minute)
  partials[interval]
end