Class: Montrose::TimeOfDay
- Inherits:
-
Object
- Object
- Montrose::TimeOfDay
- Includes:
- Comparable
- Defined in:
- lib/montrose/time_of_day.rb
Instance Attribute Summary collapse
-
#hour ⇒ Object
readonly
Returns the value of attribute hour.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#sec ⇒ Object
readonly
Returns the value of attribute sec.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
def inspect “#<Montrose::TimeOfDay #format_time(@hour):#format_time(@min):#format_time(@sec)” end.
-
#initialize(parts) ⇒ TimeOfDay
constructor
A new instance of TimeOfDay.
- #seconds_since_midnight ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(parts) ⇒ TimeOfDay
Returns a new instance of TimeOfDay.
21 22 23 24 |
# File 'lib/montrose/time_of_day.rb', line 21 def initialize(parts) @parts = parts @hour, @min, @sec = *parts end |
Instance Attribute Details
#hour ⇒ Object (readonly)
Returns the value of attribute hour.
5 6 7 |
# File 'lib/montrose/time_of_day.rb', line 5 def hour @hour end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
5 6 7 |
# File 'lib/montrose/time_of_day.rb', line 5 def min @min end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
5 6 7 |
# File 'lib/montrose/time_of_day.rb', line 5 def parts @parts end |
#sec ⇒ Object (readonly)
Returns the value of attribute sec.
5 6 7 |
# File 'lib/montrose/time_of_day.rb', line 5 def sec @sec end |
Class Method Details
.from_time(time) ⇒ Object
13 14 15 |
# File 'lib/montrose/time_of_day.rb', line 13 def self.from_time(time) new(to_parts(time)) end |
.parse(arg) ⇒ Object
7 8 9 10 11 |
# 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) ⇒ Object
17 18 19 |
# File 'lib/montrose/time_of_day.rb', line 17 def self.to_parts(time) [time.hour, time.min, time.sec] end |
Instance Method Details
#<=>(other) ⇒ Object
def inspect
"#<Montrose::TimeOfDay #{format_time(@hour)}:#{format_time(@min)}:#{format_time(@sec)}"
end
38 39 40 |
# File 'lib/montrose/time_of_day.rb', line 38 def <=>(other) to_a <=> other.to_a end |
#seconds_since_midnight ⇒ Object
26 27 28 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/montrose/time_of_day.rb', line 30 def to_a @parts end |