Class: Reservation::Schedule::Interval
- Inherits:
-
Object
- Object
- Reservation::Schedule::Interval
- Defined in:
- lib/reservation/interval.rb
Overview
a utility class to match the start and end times of an Event instance, without considering the event date
Instance Attribute Summary collapse
-
#finish ⇒ Object
Returns the value of attribute finish.
-
#start ⇒ Object
Returns the value of attribute start.
Class Method Summary collapse
Instance Method Summary collapse
-
#generate(date) ⇒ Object
build a new Event with this Interval’s start and finish times, on the given date.
-
#initialize(start, finish) ⇒ Interval
constructor
A new instance of Interval.
-
#matches?(event) ⇒ Boolean
true if the start time and finish time of the given event matches start and finish times of this Interval.
- #to_s ⇒ Object
Constructor Details
#initialize(start, finish) ⇒ Interval
Returns a new instance of Interval.
9 10 11 |
# File 'lib/reservation/interval.rb', line 9 def initialize start, finish @start, @finish = start, finish end |
Instance Attribute Details
#finish ⇒ Object
Returns the value of attribute finish.
7 8 9 |
# File 'lib/reservation/interval.rb', line 7 def finish @finish end |
#start ⇒ Object
Returns the value of attribute start.
7 8 9 |
# File 'lib/reservation/interval.rb', line 7 def start @start end |
Class Method Details
.from(start, finish) ⇒ Object
23 24 25 |
# File 'lib/reservation/interval.rb', line 23 def self.from start, finish new HourMinute.parse(start), HourMinute.parse(finish) end |
.parse(intervals) ⇒ Object
27 28 29 |
# File 'lib/reservation/interval.rb', line 27 def self.parse intervals intervals.split(',').map { |i| self.from(*i.split('-')) } end |
Instance Method Details
#generate(date) ⇒ Object
build a new Event with this Interval’s start and finish times, on the given date
19 20 21 |
# File 'lib/reservation/interval.rb', line 19 def generate date Event.new :start => start.change(date), :finish => finish.change(date) end |
#matches?(event) ⇒ Boolean
true if the start time and finish time of the given event matches start and finish times of this Interval
14 15 16 |
# File 'lib/reservation/interval.rb', line 14 def matches? event start.matches_time?(event.start) && finish.matches_time?(event.finish) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/reservation/interval.rb', line 31 def to_s "#{start}-#{finish}" end |