Class: Reservation::Schedule::Interval

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#finishObject

Returns the value of attribute finish.



7
8
9
# File 'lib/reservation/interval.rb', line 7

def finish
  @finish
end

#startObject

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

Returns:

  • (Boolean)


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_sObject



31
32
33
# File 'lib/reservation/interval.rb', line 31

def to_s
  "#{start}-#{finish}"
end