Module: PhonyNumber

Defined in:
lib/phony_number.rb,
lib/phony_number/version.rb

Defined Under Namespace

Modules: ActiveRecordExtension

Constant Summary collapse

COUNTRY_NUMBER =

Quick fix to get country_phone_number (phone number) for all relevant countries. TODO: Replace with some gem or something.

{
  'NL' => '31',
  'BE' => '32',
  'DE' => '49',
  'GB' => '44',
  'FR' => '33',
  'ES' => '34',
  'IT' => '39',
  'US' => '1',
  'AU' => '61',
  'LU' => '352'
}
VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.normalize_number(number, options = {}) ⇒ Object

This method requires a country_code attribute (eg. NL) and phone_number to be set. Options:

:country_code => The country code we should use.
:default_country_code => Some fallback code (eg. 'NL') that can be used as default (comes from phony_normalize_numbers method).


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/phony_number.rb', line 26

def self.normalize_number(number, options = {})
  return if number.blank?
  number = Phony.normalize(number) # TODO: Catch errors
  if country_number = COUNTRY_NUMBER[options[:country_code] || options[:default_country_code]]
    # Add country_number if missing
    number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
  end
  number = Phony.normalize(number)
rescue
  number # If all goes wrong .. we still return the original input.
end