class TimeRounder::RoundedTimeFromSeconds
Takes seconds and returns a decimal of hours and partial hours.
Attributes
seconds[RW]
Public Class Methods
new(seconds, schedule = 15)
click to toggle source
# File lib/time_rounder/rounded_time_from_seconds.rb, line 21 def initialize(seconds, schedule = 15) self.seconds = seconds get_schedule(schedule) end
Public Instance Methods
rounded_time()
click to toggle source
Returns the total rounded hours in the number of seconds
# File lib/time_rounder/rounded_time_from_seconds.rb, line 13 def rounded_time time = hours + quarter_hours time += 1 if add_hour? time end
Private Instance Methods
add_hour?()
click to toggle source
Determines if an hour needs to be added to total if the partial is rounding up at the end of an hour
# File lib/time_rounder/rounded_time_from_seconds.rb, line 29 def add_hour? add_hours_array.include?(minutes) end
hours()
click to toggle source
Takes the number of seconds and returns the number of hours as an integer.
# File lib/time_rounder/rounded_time_from_seconds.rb, line 35 def hours seconds / 3600 end
minutes()
click to toggle source
Takes the remainder of seconds after the hours removed and retrieve the left over minutes.
# File lib/time_rounder/rounded_time_from_seconds.rb, line 42 def minutes (seconds % 3600) / 60 end
quarter_hours()
click to toggle source
Takes the number of minutes in the total of seconds after hours are removed, to retrieve the decimal portion of the total.
# File lib/time_rounder/rounded_time_from_seconds.rb, line 49 def quarter_hours partial_hours_from_minutes(minutes) end