Class: Cyclical::MonthdaysFilter
- Inherits:
-
Object
- Object
- Cyclical::MonthdaysFilter
- Defined in:
- lib/cyclical/filters/monthdays_filter.rb
Instance Attribute Summary collapse
-
#monthdays ⇒ Object
readonly
Returns the value of attribute monthdays.
Instance Method Summary collapse
-
#initialize(*monthdays) ⇒ MonthdaysFilter
constructor
A new instance of MonthdaysFilter.
- #match?(date) ⇒ Boolean
-
#next(date) ⇒ Object
FIXME - this can probably be calculated.
- #previous(date) ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize(*monthdays) ⇒ MonthdaysFilter
Returns a new instance of MonthdaysFilter.
6 7 8 9 10 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 6 def initialize(*monthdays) raise ArgumentError, "Specify at least one day of the month" if monthdays.empty? @monthdays = monthdays.sort end |
Instance Attribute Details
#monthdays ⇒ Object (readonly)
Returns the value of attribute monthdays.
4 5 6 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 4 def monthdays @monthdays end |
Instance Method Details
#match?(date) ⇒ Boolean
12 13 14 15 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 12 def match?(date) last = date.end_of_month.day (@monthdays.include?(date.day) || @monthdays.include?(date.day - last - 1)) end |
#next(date) ⇒ Object
FIXME - this can probably be calculated
22 23 24 25 26 27 28 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 22 def next(date) until match?(date) date += 1.day end date end |
#previous(date) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 30 def previous(date) until match?(date) date -= 1.day end date end |
#step ⇒ Object
17 18 19 |
# File 'lib/cyclical/filters/monthdays_filter.rb', line 17 def step 1.day end |