class Holidays::Definition::Repository::HolidaysByMonth

Public Class Methods

new() click to toggle source
# File lib/holidays/definition/repository/holidays_by_month.rb, line 5
def initialize
  @holidays_by_month = {}
end

Public Instance Methods

add(new_holidays) click to toggle source
# File lib/holidays/definition/repository/holidays_by_month.rb, line 18
def add(new_holidays)
  new_holidays.each do |month, holiday_defs|
    @holidays_by_month[month] = [] unless @holidays_by_month[month]

    holiday_defs.each do |holiday_def|
      exists = false
      @holidays_by_month[month].each do |existing_def|
        if definition_exists?(existing_def, holiday_def)
          # append regions
          existing_def[:regions] << holiday_def[:regions]

          # Should do this once we're done
          existing_def[:regions].flatten!
          existing_def[:regions].uniq!
          exists = true
        end
      end

      @holidays_by_month[month] << holiday_def  unless exists
    end
  end
end
all() click to toggle source
# File lib/holidays/definition/repository/holidays_by_month.rb, line 9
def all
  @holidays_by_month
end
find_by_month(month) click to toggle source
# File lib/holidays/definition/repository/holidays_by_month.rb, line 13
def find_by_month(month)
  raise ArgumentError unless month >= 0 && month <= 12
  @holidays_by_month[month]
end

Private Instance Methods

definition_exists?(existing_def, target_def) click to toggle source
# File lib/holidays/definition/repository/holidays_by_month.rb, line 43
def definition_exists?(existing_def, target_def)
  existing_def[:name] == target_def[:name] && existing_def[:wday] == target_def[:wday] && existing_def[:mday] == target_def[:mday] && existing_def[:week] == target_def[:week] && existing_def[:function] == target_def[:function] && existing_def[:type] == target_def[:type] && existing_def[:observed] == target_def[:observed] && existing_def[:year_ranges] == target_def[:year_ranges]
end