Permalink
Browse files

+ Move work to the initialization stage (instead of during runtime)

  • Loading branch information...
1 parent 8464c77 commit e71e18c0f2bc96784f83a4d6ef977e5b4a591533 @floere committed Mar 18, 2013
Showing with 12 additions and 10 deletions.
  1. +4 −2 lib/phony/dsl.rb
  2. +8 −8 lib/phony/validators.rb
View
@@ -49,9 +49,11 @@ class DSL
# Example:
# country '27', # CC, followed by rules, for example fixed(2) >> ...
#
- def country country_code, country, validator = nil
+ def country country_code, country, validators = nil
Phony::CountryCodes.instance.add country_code, country
- Phony::Validators.instance.add country_code, validator if validator
+ [*validators].each do |validator|
+ Phony::Validators.instance.add country_code, validator
+ end if validators
end
# National matcher & splitters.
@@ -25,15 +25,15 @@ def initialize
@country_validators = {}
end
-
def self.instance
@instance ||= new
end
- # Add a specific country validator (or an array of validators)
+ # Add a specific country validator.
#
def add cc, validator
- @country_validators[cc] = validator
+ @country_validators[cc] ||= []
+ @country_validators[cc] << validator
end
# Is the given number plausible?
@@ -72,7 +72,7 @@ def plausible? number, hints = {}
# Country specific checks.
#
- validators = [*validator_for(cc)]
+ validators = validators_for cc
validators.map do |validator|
return false unless validator.plausible? ndc, rest
end
@@ -82,12 +82,12 @@ def plausible? number, hints = {}
return false
end
- def validator_for cc
- @country_validators[cc] || default_validator
+ def validators_for cc
+ @country_validators[cc] || default_validators
end
- def default_validator
- @default_validator ||= Validator.new
+ def default_validators
+ @default_validators ||= [Validator.new]
end
end

0 comments on commit e71e18c

Please sign in to comment.