Class: NationalHolidays

Inherits:
Object
  • Object
show all
Defined in:
lib/national_holidays.rb,
lib/national_holidays/region.rb,
lib/national_holidays/country.rb,
lib/national_holidays/holiday.rb

Defined Under Namespace

Classes: Country, Holiday, Region

Constant Summary collapse

UnknownCountryError =
Class.new(StandardError)
UnknownRegionError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.config_directoryObject



29
30
31
# File 'lib/national_holidays.rb', line 29

def self.config_directory
  File.expand_path('../national-holidays-config/conf', __dir__)
end

.countriesObject



15
16
17
# File 'lib/national_holidays.rb', line 15

def self.countries
  Country.all
end

.load!Object



10
11
12
13
# File 'lib/national_holidays.rb', line 10

def self.load!
  Region.all.each(&:name)
  true
end

.regionsObject



19
20
21
# File 'lib/national_holidays.rb', line 19

def self.regions
  Region.all
end

.regions_to_public_holiday_count_for_year(year) ⇒ Object



23
24
25
26
27
# File 'lib/national_holidays.rb', line 23

def self.regions_to_public_holiday_count_for_year(year)
  Region.all.sort_by(&:code).map do |region|
    [region.code, region.holidays_between(Date.new(year, 1, 1), Date.new(year, 12, 31)).count]
  end.to_h
end