class TimeRounder::RoundedTime
Round a Time/DateTime object to Quarter Hours 0, 15, 30, 45
Attributes
time[RW]
Public Class Methods
new(time, schedule = 15)
click to toggle source
initailize the object with a date/time object
# File lib/time_rounder/rounded_time.rb, line 25 def initialize(time, schedule = 15) self.time = time get_schedule(schedule) end
Public Instance Methods
rounded_time()
click to toggle source
returns the DateTime/Time object on the correct quarter hour
# File lib/time_rounder/rounded_time.rb, line 13 def rounded_time number_to_add = magic_number seconds_to_remove = (time.sec + (minutes * 60)) self.time -= seconds_to_remove self.time += number_to_add time end
Private Instance Methods
magic_number()
click to toggle source
The number of seconds to add to the time to get to the nearest quarter hour
# File lib/time_rounder/rounded_time.rb, line 33 def magic_number minutes_to_closest_partial(minutes) * 60 end
minutes()
click to toggle source
The minutes of the date/time object
# File lib/time_rounder/rounded_time.rb, line 39 def minutes time.strftime('%M').to_i end