class Holiday
Constants
- CALENDARS_FILENAME
Attributes
calendars[R]
Public Class Methods
new(calendars)
click to toggle source
# File lib/holiday.rb, line 13 def initialize(calendars) @calendars = calendars end
Public Instance Methods
in(year)
click to toggle source
# File lib/holiday.rb, line 17 def in(year) holidays[year] end
load_data()
click to toggle source
# File lib/holiday.rb, line 21 def load_data # TODO: remove this in a major version holidays calendars end
Private Instance Methods
by_year(holidays_by_year, date)
click to toggle source
# File lib/holiday.rb, line 34 def by_year(holidays_by_year, date) holidays_by_year ||= {} holidays_by_year[date.year] ||= [] holidays_by_year[date.year] << date holidays_by_year end
holiday_file(calendar)
click to toggle source
# File lib/holiday.rb, line 45 def holiday_file(calendar) filename = holiday_filename(calendar) return if filename.nil? path = File.dirname(__FILE__) + "/../data/#{filename}" JSON.parse(File.read(File.expand_path(path))) end
holiday_filename(calendar)
click to toggle source
# File lib/holiday.rb, line 54 def holiday_filename(calendar) holiday_files.select do |_filename, calendar_names| calendar_names.include?(calendar) end.keys.first end
holiday_files()
click to toggle source
# File lib/holiday.rb, line 60 def holiday_files @holiday_files ||= JSON.parse(File.read(CALENDARS_FILENAME)) @holiday_files end
holidays()
click to toggle source
# File lib/holiday.rb, line 29 def holidays @holidays ||= calendars.flat_map(&method(:to_holidays)).uniq. reduce({}, &method(:by_year)) end
to_holidays(calendar)
click to toggle source
# File lib/holiday.rb, line 41 def to_holidays(calendar) holiday_file(calendar).map(&:to_date) end