class Montrose::TimeOfDay
Attributes
hour[R]
min[R]
parts[R]
sec[R]
Public Class Methods
from_time(time)
click to toggle source
# File lib/montrose/time_of_day.rb, line 13 def self.from_time(time) new(to_parts(time)) end
new(parts)
click to toggle source
# File lib/montrose/time_of_day.rb, line 21 def initialize(parts) @parts = parts @hour, @min, @sec = *parts end
parse(arg)
click to toggle source
# File lib/montrose/time_of_day.rb, line 7 def self.parse(arg) return new(arg) if arg.is_a?(Array) from_time(::Montrose::Utils.as_time(arg)) end
to_parts(time)
click to toggle source
# File lib/montrose/time_of_day.rb, line 17 def self.to_parts(time) [time.hour, time.min, time.sec] end
Public Instance Methods
<=>(other)
click to toggle source
def inspect
"#<Montrose::TimeOfDay #{format_time(@hour)}:#{format_time(@min)}:#{format_time(@sec)}"
end
# File lib/montrose/time_of_day.rb, line 38 def <=>(other) to_a <=> other.to_a end
seconds_since_midnight()
click to toggle source
# File lib/montrose/time_of_day.rb, line 26 def seconds_since_midnight @seconds_since_midnight ||= (@hour * 60 * 60) + (@min * 60) + @sec end
to_a()
click to toggle source
# File lib/montrose/time_of_day.rb, line 30 def to_a @parts end
Private Instance Methods
format_time(part)
click to toggle source
# File lib/montrose/time_of_day.rb, line 44 def format_time(part) format("%02d", part) end