Class: Reservation::Schedule::Daily
- Inherits:
-
Object
- Object
- Reservation::Schedule::Daily
- Defined in:
- lib/reservation/daily.rb
Overview
a utility class to represent an interval starting on a day
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#nth_of_month ⇒ Object
Returns the value of attribute nth_of_month.
-
#wday ⇒ Object
Returns the value of attribute wday.
Instance Method Summary collapse
- #generate(date, list) ⇒ Object
- #good_day?(date) ⇒ Boolean
-
#initialize(wday, nth_of_month, interval) ⇒ Daily
constructor
A new instance of Daily.
- #matches?(event) ⇒ Boolean
- #to_s ⇒ Object
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
#interval ⇒ Object
Returns the value of attribute interval.
9 10 11 |
# File 'lib/reservation/daily.rb', line 9 def interval @interval end |
#nth_of_month ⇒ Object
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 |
#wday ⇒ Object
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
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
17 18 19 |
# File 'lib/reservation/daily.rb', line 17 def matches? event good_day?(event.start.to_date) && interval.matches?(event) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/reservation/daily.rb', line 31 def to_s "#{MAP_DAY[wday]} => #{interval}" end |