class Ferryman::RoutingRule
Constants
- MATCH_ALL
- STRATEGIES
Attributes
providers[R]
strategy[R]
Public Class Methods
new()
click to toggle source
# File lib/ferryman.rb, line 22 def initialize @providers = [] @match_rules = [] @strategy = 'first' end
Public Instance Methods
accept?(phone_number)
click to toggle source
# File lib/ferryman.rb, line 28 def accept?(phone_number) matched = true @match_rules.each do |rule| matched &&= rule.call(phone_number) break unless matched end matched end
add_provider(provider)
click to toggle source
# File lib/ferryman.rb, line 63 def add_provider(provider) raise ConfigError.new('provider cannot be nil!') if provider.nil? @providers << provider end
set_match(match)
click to toggle source
# File lib/ferryman.rb, line 39 def set_match(match) raise ConfigError.new('match cannot be nil!') if match.nil? if match == '*' @match_rules << MATCH_ALL elsif match.respond_to? 'has_key?' if match.has_key?(:regions) regions = Array.new(match[:regions]) @match_rules << lambda do |number| parsed_number = GlobalPhone.parse(number) regions.include? parsed_number.territory.name end end else raise ConfigError.new("Unexpected value for 'match'") end true end
strategy=(strategy)
click to toggle source
# File lib/ferryman.rb, line 68 def strategy=(strategy) raise ConfigError.new('unknown strategy') unless STRATEGIES.has_key?(strategy) @strategy = strategy end