Class: Holidays::Definition::Repository::Cache
- Inherits:
-
Object
- Object
- Holidays::Definition::Repository::Cache
- Defined in:
- lib/holidays/definition/repository/cache.rb
Instance Method Summary collapse
- #cache_between(start_date, end_date, cache_data, *options) ⇒ Object
- #find(start_date, end_date, *options) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
5 6 7 |
# File 'lib/holidays/definition/repository/cache.rb', line 5 def initialize reset! end |
Instance Method Details
#cache_between(start_date, end_date, cache_data, *options) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/holidays/definition/repository/cache.rb', line 9 def cache_between(start_date, end_date, cache_data, *) raise ArgumentError unless cache_data @cache_range[] = start_date..end_date @cache[] = cache_data end |
#find(start_date, end_date, *options) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/holidays/definition/repository/cache.rb', line 16 def find(start_date, end_date, *) if range = @cache_range[] if range.begin <= start_date && range.end >= end_date return @cache[].select do |holiday| holiday[:date] >= start_date && holiday[:date] <= end_date end end end end |
#reset! ⇒ Object
26 27 28 29 |
# File 'lib/holidays/definition/repository/cache.rb', line 26 def reset! @cache = {} @cache_range = {} end |