require "json" require "singleton" class Holiday include Singleton attr_reader :holidays def self.load_data instance.load_data end def load_data @holidays = {} file = File.expand_path(File.dirname(__FILE__) + "/../data/holidays.json") raw_data = File.read(file) parsed = JSON.parse(raw_data) parsed.map do |str| splitted = str.split("-") date = Date.parse(str) @holidays[date.year] ||= [] @holidays[date.year] << date end @holidays end def self.in(year) load_data if instance.holidays.nil? holidays = instance.holidays[year] holidays end end