Class: Referral::FiltersTokens

Inherits:
Object
  • Object
show all
Defined in:
lib/referral/filters_tokens.rb

Instance Method Summary collapse

Instance Method Details

#call(tokens, options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/referral/filters_tokens.rb', line 51

def call(tokens, options)
  filters = options.to_h.select { |opt_name, opt_val|
    FILTER_FUNCTIONS.key?(opt_name) && !opt_val.nil?
  }

  if !filters.empty?
    tokens.filter { |token|
      filters.all? { |(opt_name, opt_val)|
        FILTER_FUNCTIONS[opt_name].call(token, opt_val)
      }
    }
  else
    result
  end
end