Class: Holidays::Definition::Repository::HolidaysByMonth

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/definition/repository/holidays_by_month.rb

Instance Method Summary collapse

Constructor Details

#initializeHolidaysByMonth

Returns a new instance of HolidaysByMonth.



5
6
7
# File 'lib/holidays/definition/repository/holidays_by_month.rb', line 5

def initialize
  @holidays_by_month = {}
end

Instance Method Details

#add(new_holidays) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

#allObject



9
10
11
# File 'lib/holidays/definition/repository/holidays_by_month.rb', line 9

def all
  @holidays_by_month
end

#find_by_month(month) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
# 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