class ToPhone::Parser

Public Class Methods

to_phone(number, country_code = '1') click to toggle source
# File lib/to_phone.rb, line 14
def self.to_phone number, country_code = '1'
  begin
    number = number.strip
    country_code = country_code.strip
    country_code = '1' if country_code.nil? || country_code.empty?
    country_code = country_code.to_s
    number = number[country_code.length..-1] if number[0...country_code.length] == country_code
    phone = Phoner::Phone.parse(number, country_code: country_code)
    return phone
  rescue Phoner::PhoneError
    return nil
  end
end