class Holidays::Definition::Repository::Cache

Public Class Methods

new() click to toggle source
# File lib/holidays/definition/repository/cache.rb, line 5
def initialize
  reset!
end

Public Instance Methods

cache_between(start_date, end_date, cache_data, *options) click to toggle source
# File lib/holidays/definition/repository/cache.rb, line 9
def cache_between(start_date, end_date, cache_data, *options)
  raise ArgumentError unless cache_data

  @cache_range[options] = start_date..end_date
  @cache[options] = cache_data
end
find(start_date, end_date, *options) click to toggle source
# File lib/holidays/definition/repository/cache.rb, line 16
def find(start_date, end_date, *options)
  if range = @cache_range[options]
    if range.begin <= start_date && range.end >= end_date
      return @cache[options].select do |holiday|
        holiday[:date] >= start_date && holiday[:date] <= end_date
      end
    end
  end
end
reset!() click to toggle source
# File lib/holidays/definition/repository/cache.rb, line 26
def reset!
  @cache = {}
  @cache_range = {}
end