Class: HolidayCo::HolidayCalculator
- Inherits:
-
Object
- Object
- HolidayCo::HolidayCalculator
- Defined in:
- lib/holiday_co/holiday_calculator.rb
Instance Attribute Summary collapse
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
-
#calculate ⇒ Object
Results are deep-frozen: they are shared through the cache across callers and threads, so they must be immutable.
-
#initialize(year) ⇒ HolidayCalculator
constructor
A new instance of HolidayCalculator.
Constructor Details
#initialize(year) ⇒ HolidayCalculator
Returns a new instance of HolidayCalculator.
20 21 22 |
# File 'lib/holiday_co/holiday_calculator.rb', line 20 def initialize(year) @year = year end |
Instance Attribute Details
#year ⇒ Object (readonly)
Returns the value of attribute year.
11 12 13 |
# File 'lib/holiday_co/holiday_calculator.rb', line 11 def year @year end |
Class Method Details
.for(year) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/holiday_co/holiday_calculator.rb', line 13 def self.for(year) year = year.to_i return new(year).calculate unless HolidayCo.cache_enabled? HolidayCo.cache.fetch(year) { new(year).calculate } end |
Instance Method Details
#calculate ⇒ Object
Results are deep-frozen: they are shared through the cache across callers and threads, so they must be immutable.
26 27 28 29 30 31 32 |
# File 'lib/holiday_co/holiday_calculator.rb', line 26 def calculate [fixed_holidays, pascua_holidays, movable_holidays] .flatten .sort_by! { |h| h[:date] } .each { |h| h[:date].freeze; h.freeze } .freeze end |