Class: Cyclical::YeardaysFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclical/filters/yeardays_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*yeardays) ⇒ YeardaysFilter

Returns a new instance of YeardaysFilter.

Raises:

  • (ArgumentError)


6
7
8
9
10
# File 'lib/cyclical/filters/yeardays_filter.rb', line 6

def initialize(*yeardays)
  raise ArgumentError, "Specify at least one day of the month" if yeardays.empty?

  @yeardays = yeardays.sort
end

Instance Attribute Details

#yeardaysObject (readonly)

Returns the value of attribute yeardays.



4
5
6
# File 'lib/cyclical/filters/yeardays_filter.rb', line 4

def yeardays
  @yeardays
end

Instance Method Details

#match?(date) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/cyclical/filters/yeardays_filter.rb', line 12

def match?(date)
  last = date.end_of_year.yday
  (@yeardays.include?(date.yday) || @yeardays.include?(date.yday - last - 1))
end

#next(date) ⇒ Object

FIXME - traverse the days directly



22
23
24
25
26
27
28
# File 'lib/cyclical/filters/yeardays_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/yeardays_filter.rb', line 30

def previous(date)
  until match?(date)
    date -= 1.day
  end

  date
end

#stepObject



17
18
19
# File 'lib/cyclical/filters/yeardays_filter.rb', line 17

def step
  1.day
end