Module: Countries::PhoneNumbers::Extensions::ClassMethods
- Defined in:
- lib/countries/phone_numbers/extensions.rb
Instance Method Summary collapse
-
#find_all_by_phone_number(number) ⇒ Object
Find all possible countries for the given telephone number.
-
#find_all_countries_by_phone_number(number) ⇒ Object
Find all possible countries for the given telephone number.
-
#find_by_phone_number(number) ⇒ Object
Find the first country by the given telephone number.
-
#find_country_by_phone_number(number) ⇒ Object
Find the first country by the given telephone number.
- #normalize_phone_number(number) ⇒ Object
- #plausible_phone_number?(number) ⇒ Boolean
- #tokenize_phone_number(number) ⇒ Object
Instance Method Details
#find_all_by_phone_number(number) ⇒ Object
Find all possible countries for the given telephone number. Generally we try to eliminate duplicates by using country code specific detectors.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
Find all possible countries for the given telephone number. Generally we try to eliminate duplicates by using country code specific detectors.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
Find the first country by the given telephone number. Returns an array of country code and data
23 24 25 26 |
# 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) ⇒ Object
Find the first country by the given telephone number. Returns the country object itself.
51 52 53 54 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/countries/phone_numbers/extensions.rb', line 13 def normalize_phone_number( number ) Phony.normalize( number ) end |
#plausible_phone_number?(number) ⇒ Boolean
9 10 11 |
# File 'lib/countries/phone_numbers/extensions.rb', line 9 def plausible_phone_number?( number ) Phony.plausible?( number ) end |
#tokenize_phone_number(number) ⇒ Object
17 18 19 |
# File 'lib/countries/phone_numbers/extensions.rb', line 17 def tokenize_phone_number( number ) Phony.split( normalize_phone_number( number ) ) end |