Class: OpeningHours::OpenHours
- Inherits:
-
Object
- Object
- OpeningHours::OpenHours
- Defined in:
- lib/opening_hours.rb
Constant Summary collapse
- CLOSED =
new(0, 0)
Instance Attribute Summary collapse
-
#close ⇒ Object
readonly
Returns the value of attribute close.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
Class Method Summary collapse
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(open, close) ⇒ OpenHours
constructor
A new instance of OpenHours.
- #offset(seconds) ⇒ Object
Constructor Details
#initialize(open, close) ⇒ OpenHours
Returns a new instance of OpenHours.
12 13 14 |
# File 'lib/opening_hours.rb', line 12 def initialize(open, close) @open, @close = open, close end |
Instance Attribute Details
#close ⇒ Object (readonly)
Returns the value of attribute close.
10 11 12 |
# File 'lib/opening_hours.rb', line 10 def close @close end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
10 11 12 |
# File 'lib/opening_hours.rb', line 10 def open @open end |
Class Method Details
.parse(open, close) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/opening_hours.rb', line 22 def self.parse(open, close) open = Time.zone.parse(open) close = Time.zone.parse(close) open = TimeUtils::seconds_from_midnight(open) close = TimeUtils::seconds_from_midnight(close) new(open, close) end |
Instance Method Details
#duration ⇒ Object
16 17 18 |
# File 'lib/opening_hours.rb', line 16 def duration @duration ||= @open < @close ? @close - @open : 0 end |
#offset(seconds) ⇒ Object
32 33 34 |
# File 'lib/opening_hours.rb', line 32 def offset(seconds) self.class.new([@open, seconds].max, @close) end |