class Cyclical::MonthsFilter
Constants
- MONTH_NAMES
Attributes
months[R]
Public Class Methods
new(*months)
click to toggle source
# File lib/cyclical/filters/months_filter.rb, line 21 def initialize(*months) raise ArgumentError, "Specify at least one month" if months.empty? @months = months.map { |m| m.is_a?(Integer) ? m : MONTH_NAMES[m.to_sym] }.sort end
Public Instance Methods
match?(date)
click to toggle source
# File lib/cyclical/filters/months_filter.rb, line 27 def match?(date) @months.include?(date.mon) end
next(date)
click to toggle source
# File lib/cyclical/filters/months_filter.rb, line 35 def next(date) return date if match?(date) if month = @months.find { |m| m > date.month } date.beginning_of_year + (month - 1).months + date.hour.hours + date.min.minutes + date.sec.seconds else date.beginning_of_year + 1.year + (@months.first - 1).months + date.hour.hours + date.min.minutes + date.sec.seconds end end
previous(date)
click to toggle source
# File lib/cyclical/filters/months_filter.rb, line 45 def previous(date) return date if match?(date) if month = @months.reverse.find { |m| m < date.month } date.beginning_of_year + month.months - 1.day + date.hour.hours + date.min.minutes + date.sec.seconds else date.beginning_of_year - 1.year + @months.last.months - 1.day + date.hour.hours + date.min.minutes + date.sec.seconds end end
step()
click to toggle source
# File lib/cyclical/filters/months_filter.rb, line 31 def step 1.month end