class Montrose::Rule::NthDayOfYear
Public Class Methods
apply_options(opts)
click to toggle source
# File lib/montrose/rule/nth_day_of_year.rb, line 12 def self.apply_options(opts) opts[:day] end
apply_options?(opts)
click to toggle source
# File lib/montrose/rule/nth_day_of_year.rb, line 8 def self.apply_options?(opts) opts[:every] == :year && !opts[:month] && opts[:day].is_a?(Hash) end
new(days)
click to toggle source
Initializes rule
@param [Hash] days - valid days of week to year occurrence pairs
# File lib/montrose/rule/nth_day_of_year.rb, line 20 def initialize(days) @days = days end
Public Instance Methods
include?(time)
click to toggle source
# File lib/montrose/rule/nth_day_of_year.rb, line 24 def include?(time) @days.key?(time.wday) && nth_day?(time) end
Private Instance Methods
nth_day?(time)
click to toggle source
# File lib/montrose/rule/nth_day_of_year.rb, line 30 def nth_day?(time) expected_occurrences = @days[time.wday] nth_day = NthDayMatcher.new(time.wday, YearDay.new(time)) expected_occurrences.any? { |n| nth_day.matches?(n) } end