Class: Holidays::UseCase::Context::YearHoliday

Inherits:
Object
  • Object
show all
Includes:
ContextCommon
Defined in:
lib/holidays/use_case/context/year_holiday.rb

Instance Method Summary collapse

Methods included from ContextCommon

#call_proc, #in_region?, #make_date_array

Constructor Details

#initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo) ⇒ YearHoliday

Returns a new instance of YearHoliday.



7
8
9
10
11
12
# File 'lib/holidays/use_case/context/year_holiday.rb', line 7

def initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo)
  @holidays_by_month_repo = holidays_by_month_repo
  @day_of_month_calculator = day_of_month_calculator
  @custom_methods_repo = custom_methods_repo
  @proc_result_cache_repo = proc_result_cache_repo
end

Instance Method Details

#call(from_date, to_date, dates_driver, regions, observed, informal) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/holidays/use_case/context/year_holiday.rb', line 14

def call(from_date, to_date, dates_driver, regions, observed, informal)
  validate!(from_date, to_date, dates_driver, regions)
  holidays = []
  ret_holidays = []

  ret_holidays = make_date_array(dates_driver, regions, observed, informal)
  ret_holidays.each do |holiday|
    if holiday[:date] >= from_date && holiday[:date] <= to_date
      holidays << holiday
    end
  end

  holidays.sort{|a, b| a[:date] <=> b[:date] }
end