moduleHolidaysmoduleFindermoduleContextclassSearchdefinitialize(holidays_by_month_repo,custom_method_processor,day_of_month_calculator,rules)@holidays_by_month_repo=holidays_by_month_repo@custom_method_processor=custom_method_processor@day_of_month_calculator=day_of_month_calculator@rules=rulesenddefcall(dates_driver,regions,options)validate!(dates_driver)holidays=[]dates_driver.eachdo|year,months|months.eachdo|month|nextunlesshbm=@holidays_by_month_repo.find_by_month(month)hbm.eachdo|h|nextifinformal_type?(h[:type])&&!informal_set?(options)nextunless@rules[:in_region].call(regions,h[:regions])ifh[:year_ranges]nextunless@rules[:year_range].call(year,h[:year_ranges])enddate=build_date(year,month,h)nextunlessdateifobserved_set?(options)&&h[:observed]date=build_observed_date(date,regions,h)endholidays<<{:date=>date,:name=>h[:name],:regions=>h[:regions]}endendendholidays.sort_by.with_indexdo|h,i|direct=h[:regions].any?{|r|regions.include?(r)}?0:1[direct,i]endendprivatedefvalidate!(dates_driver)#FIXME This should give some kind of error message that indicates the# problem.raiseArgumentErrorifdates_driver.nil?||dates_driver.empty?dates_driver.eachdo|year,months|months.eachdo|month|raiseArgumentErrorunlessmonth>=0&&month<=12endendenddefinformal_type?(type)type&&[:informal,'informal'].include?(type)enddefinformal_set?(options)options&&options.include?(:informal)==trueenddefobserved_set?(options)options&&options.include?(:observed)==trueenddefbuild_date(year,month,h)ifh[:function]holiday=custom_holiday(year,month,h)#FIXME The result should always be present, see https://github.com/holidays/holidays/issues/204 for more informationcurrent_month=holiday&.monthcurrent_day=holiday&.mdayelsecurrent_month=monthcurrent_day=h[:mday]||@day_of_month_calculator.call(year,month,h[:week],h[:wday])end# Silently skip bad mdays#TODO Should we be doing something different here? We have no concept of logging right now. Maybe we should add it?Date.civil(year,current_month,current_day)rescuenilenddefcustom_holiday(year,month,h)@custom_method_processor.call(#FIXME This seems like a bug, we seem to expect the day in here in the au defs?build_custom_method_input(year,month,h[:mday],h[:regions]),h[:function],h[:function_arguments],h[:function_modifier],)enddefbuild_custom_method_input(year,month,day,regions){year: year,month: month,day: day,region: regions.first,#FIXME This isn't ideal but will work for our current use case...}enddefbuild_observed_date(date,regions,h)@custom_method_processor.call(build_custom_method_input(date.year,date.month,date.day,regions),h[:observed],[:date],)endendendendend