class Montrose::TimeOfDay
Attributes
Public Class Methods
Source
# File lib/montrose/time_of_day.rb, line 13 def self.from_time(time) new(to_parts(time)) end
Source
# File lib/montrose/time_of_day.rb, line 21 def initialize(parts) @parts = parts @hour, @min, @sec = *parts end
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
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
Source
# File lib/montrose/time_of_day.rb, line 38 def <=>(other) to_a <=> other.to_a end
def inspect
"#<Montrose::TimeOfDay #{format_time(@hour)}:#{format_time(@min)}:#{format_time(@sec)}"
end
Source
# File lib/montrose/time_of_day.rb, line 26 def seconds_since_midnight @seconds_since_midnight ||= (@hour * 60 * 60) + (@min * 60) + @sec end
Private Instance Methods
Source
# File lib/montrose/time_of_day.rb, line 44 def format_time(part) format("%02d", part) end