class Repeatable::Expression::WeekdayInMonth
Attributes
count[R]
weekday[R]
Public Class Methods
new(weekday:, count:)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 9 def initialize(weekday:, count:) @weekday = weekday @count = count end
Public Instance Methods
include?(date)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 15 def include?(date) day_matches?(date) && week_matches?(date) end
Private Instance Methods
day_matches?(date)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 28 def day_matches?(date) date.wday == weekday end
negative_count?()
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 57 def negative_count? count < 0 end
week_from_beginning(date)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 42 def week_from_beginning(date) week_in_month(date.day - 1) end
week_from_end(date)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 47 def week_from_end(date) -week_in_month(last_date_of_month(date).day - date.day) end
week_in_month(zero_indexed_day)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 52 def week_in_month(zero_indexed_day) (zero_indexed_day / 7) + 1 end
week_matches?(date)
click to toggle source
# File lib/repeatable/expression/weekday_in_month.rb, line 33 def week_matches?(date) if negative_count? week_from_end(date) == count else week_from_beginning(date) == count end end