Class: Blackcal::TimeOfDay
- Inherits:
-
Object
- Object
- Blackcal::TimeOfDay
- Includes:
- Comparable
- Defined in:
- lib/blackcal/time_of_day.rb
Overview
Represents a time of day (hour and min)
Instance Attribute Summary collapse
-
#hour ⇒ Integer
readonly
Hour.
-
#min ⇒ Integer
readonly
Minutes defaults to 0.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares two time of days.
-
#initialize(hour, min = nil) ⇒ TimeOfDay
constructor
Initialize time of day.
Constructor Details
#initialize(hour, min = nil) ⇒ TimeOfDay
Initialize time of day
17 18 19 20 |
# File 'lib/blackcal/time_of_day.rb', line 17 def initialize(hour, min = nil) @hour = hour @min = min || 0 end |
Instance Attribute Details
#hour ⇒ Integer (readonly)
Returns hour.
9 10 11 |
# File 'lib/blackcal/time_of_day.rb', line 9 def hour @hour end |
#min ⇒ Integer (readonly)
Returns minutes defaults to 0.
12 13 14 |
# File 'lib/blackcal/time_of_day.rb', line 12 def min @min end |
Instance Method Details
#<=>(other) ⇒ Integer
Compares two time of days
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/blackcal/time_of_day.rb', line 25 def <=>(other) other_seconds = if other.is_a?(self.class) (other.hour * 60 * 60) + (other.min * 60) else other * 60 * 60 end seconds = (hour * 60 * 60) + (min * 60) seconds <=> other_seconds end |