Class: Holidays::Finder::Rules::InRegion

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

Class Method Summary collapse

Class Method Details

.call(requested, available) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/holidays/finder/rules/in_region.rb', line 6

def call(requested, available)
  return true if requested.include?(:any)

  # When an underscore is encountered, derive the parent regions
  # symbol and check for both.
  requested = requested.collect do |r|
    if r.to_s =~ /_/
      chunks = r.to_s.split('_')

      chunks.length.downto(1).map do |num|
        chunks[0..-num].join('_').to_sym
      end
    else
      r
    end
  end

  requested = requested.flatten.uniq

  available.any? { |avail| requested.include?(avail) }
end