module Countries::PhoneNumbers::Extensions::ClassMethods
Public Instance Methods
find_all_by_phone_number( number )
click to toggle source
Find all possible countries for the given telephone number. Generally we try to eliminate duplicates by using country code specific detectors.
# File lib/countries/phone_numbers/extensions.rb, line 31 def find_all_by_phone_number( number ) normalised_number = tokenize_phone_number( number ) country_code = normalised_number.first # Is this a detector country? detector = phone_number_detector_factory.detector_for( country_code ) if detector return detector.find_all_by_phone_number( normalised_number ) # Otherwise ask the general code base for the number else return Country.find_all_by_country_code( country_code ) end rescue return nil end
find_all_countries_by_phone_number( number )
click to toggle source
Find all possible countries for the given telephone number. Generally we try to eliminate duplicates by using country code specific detectors.
# File lib/countries/phone_numbers/extensions.rb, line 59 def find_all_countries_by_phone_number( number ) normalised_number = tokenize_phone_number( number ) country_code = normalised_number.first # Is this a detector country? detector = phone_number_detector_factory.detector_for( country_code ) if detector return detector.find_all_countries_by_phone_number( normalised_number ) # Otherwise ask Country for the number else return Country.find_all_countries_by_country_code( country_code ) end rescue return nil end
find_by_phone_number( number )
click to toggle source
Find the first country by the given telephone number. Returns an array of country code and data
# File lib/countries/phone_numbers/extensions.rb, line 23 def find_by_phone_number( number ) found = find_all_by_phone_number(number) found.nil? ? nil : found.first end
find_country_by_phone_number( number )
click to toggle source
Find the first country by the given telephone number. Returns the country object itself.
# File lib/countries/phone_numbers/extensions.rb, line 51 def find_country_by_phone_number( number ) found = find_all_countries_by_phone_number(number) found.nil? ? nil : found.first end
normalize_phone_number( number )
click to toggle source
# File lib/countries/phone_numbers/extensions.rb, line 13 def normalize_phone_number( number ) Phony.normalize( number ) end
plausible_phone_number?( number )
click to toggle source
# File lib/countries/phone_numbers/extensions.rb, line 9 def plausible_phone_number?( number ) Phony.plausible?( number ) end
tokenize_phone_number( number )
click to toggle source
# File lib/countries/phone_numbers/extensions.rb, line 17 def tokenize_phone_number( number ) Phony.split( normalize_phone_number( number ) ) end
Protected Instance Methods
phone_number_detector_factory()
click to toggle source
# File lib/countries/phone_numbers/extensions.rb, line 79 def phone_number_detector_factory @@phone_number_detector_factory ||= Countries::PhoneNumbers::DetectorFactory.new end