Class: Holidays::UseCase::Context::NextHoliday
- Inherits:
-
Object
- Object
- Holidays::UseCase::Context::NextHoliday
- Includes:
- ContextCommon
- Defined in:
- lib/holidays/use_case/context/next_holiday.rb
Instance Method Summary collapse
- #call(holidays_count, from_date, dates_driver, regions, observed, informal) ⇒ Object
-
#initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo) ⇒ NextHoliday
constructor
A new instance of NextHoliday.
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) ⇒ NextHoliday
Returns a new instance of NextHoliday.
7 8 9 10 11 12 |
# File 'lib/holidays/use_case/context/next_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(holidays_count, from_date, dates_driver, regions, observed, informal) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/holidays/use_case/context/next_holiday.rb', line 14 def call(holidays_count, from_date, dates_driver, regions, observed, informal) validate!(holidays_count, from_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 holidays << holiday holidays_count -= 1 break if holidays_count == 0 end end holidays.sort{|a, b| a[:date] <=> b[:date] } end |