Module: TimeRounder::Schedule::FifteenMinute

Defined in:
lib/time_rounder/schedule/fifteen_minute.rb

Overview

Schedule to round on 00, 15, 30, 45

Instance Method Summary collapse

Instance Method Details

#add_hours_arrayObject

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



9
10
11
# 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) ⇒ Object



31
32
33
# 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_intervalsObject



13
14
15
# File 'lib/time_rounder/schedule/fifteen_minute.rb', line 13

def minute_intervals
  [0, 15, 30, 45, 60]
end

#minutes_to_closest_partial(minute) ⇒ Object

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



27
28
29
# 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) ⇒ Object

returns the partial hour total based on what the minute is



19
20
21
22
23
# 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