12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/holidays/finder/context/search.rb', line 12
def call(dates_driver, regions, options)
validate!(dates_driver)
holidays = []
dates_driver.each do |year, months|
months.each do |month|
next unless hbm = @holidays_by_month_repo.find_by_month(month)
hbm.each do |h|
next if informal_type?(h[:type]) && !informal_set?(options)
next unless @rules[:in_region].call(regions, h[:regions])
if h[:year_ranges]
next unless @rules[:year_range].call(year, h[:year_ranges])
end
current_month = month
current_day = h[:mday]
if h[:function]
result = @custom_method_processor.call(
build_custom_method_input(year, current_month, current_day, h[:regions]),
h[:function], h[:function_arguments], h[:function_modifier],
)
if result
current_month = result.month
current_day = result.mday
else
current_month = nil
current_day = nil
end
else
current_day = h[:mday] || @day_of_month_calculator.call(year, current_month, h[:week], h[:wday])
end
begin
date = Date.civil(year, current_month, current_day)
rescue; next; end
if observed_set?(options) && h[:observed]
date = @custom_method_processor.call(
build_custom_method_input(date.year, date.month, date.day, regions),
h[:observed],
[:date],
)
end
holidays << {:date => date, :name => h[:name], :regions => h[:regions]}
end
end
end
holidays
end
|