Method: Phonelib::PhoneFormatter#international
- Defined in:
- lib/phonelib/phone_formatter.rb
#international(formatted = true, prefix = '+') ⇒ String
Returns e164 formatted phone number. Method can receive single string parameter that will be defined as prefix
| 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # File 'lib/phonelib/phone_formatter.rb', line 52 def international(formatted = true, prefix = '+') prefix = formatted if formatted.is_a?(String) return nil if sanitized.empty? return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless possible? return "#{prefix}#{data_country_code}#{@national_number}" unless formatted fmt = @data[country][:format] national = @national_number if (matches = @national_number.match(cr(fmt[Core::PATTERN]))) fmt = fmt[:intl_format] || fmt[:format] national = fmt.gsub(/\$\d/) { |el| matches[el[1].to_i] } unless fmt == 'NA' end "#{prefix}#{data_country_code} #{national}" end |