Class: Reservation::Schedule::Daily

Inherits:
Object
  • Object
show all
Defined in:
lib/reservation/daily.rb

Overview

a utility class to represent an interval starting on a day

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wday, nth_of_month, interval) ⇒ Daily

Returns a new instance of Daily.



11
12
13
14
15
# File 'lib/reservation/daily.rb', line 11

def initialize wday, nth_of_month, interval
  @wday = wday
  @nth_of_month = nth_of_month
  @interval = interval
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



9
10
11
# File 'lib/reservation/daily.rb', line 9

def interval
  @interval
end

#nth_of_monthObject

Returns the value of attribute nth_of_month.



9
10
11
# File 'lib/reservation/daily.rb', line 9

def nth_of_month
  @nth_of_month
end

#wdayObject

Returns the value of attribute wday.



9
10
11
# File 'lib/reservation/daily.rb', line 9

def wday
  @wday
end

Instance Method Details

#generate(date, list) ⇒ Object



21
22
23
24
25
# File 'lib/reservation/daily.rb', line 21

def generate date, list
  return list unless good_day?(date)
  list << interval.generate(date)
  list
end

#good_day?(date) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/reservation/daily.rb', line 27

def good_day? date
  (date.wday == self.wday) && ((self.nth_of_month == :all) || date.nth_day_of_month?(self.nth_of_month))
end

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/reservation/daily.rb', line 17

def matches? event
  good_day?(event.start.to_date) && interval.matches?(event)
end

#to_sObject



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

def to_s
  "#{MAP_DAY[wday]} => #{interval}"
end