Class: Holidays::Finder::Rules::YearRange

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/finder/rules/year_range.rb

Constant Summary collapse

UNTIL =
:until
FROM =
:from
LIMITED =
:limited
BETWEEN =
:between

Class Method Summary collapse

Class Method Details

.call(target_year, year_range_defs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/holidays/finder/rules/year_range.rb', line 11

def call(target_year, year_range_defs)
  validate!(target_year, year_range_defs)

  operator = year_range_defs.keys.first
  rule_value = year_range_defs[operator]

  case operator
  when UNTIL
    matched = target_year <= rule_value
  when FROM
    matched = target_year >= rule_value
  when LIMITED
    matched = rule_value.include?(target_year)
  when BETWEEN
    matched = rule_value.cover?(target_year)
  else
    matched = false
  end

  matched
end