lib/phonelib/phone_formatter.rb
# Returns e164 formatted phone number. Method can receive single string parameter that will be defined as prefix
# @param formatted [Boolean] whether to return numbers only or formatted
# @param prefix [String] prefix to be placed before the number, "+" by default
# @return [String] formatted international number
Returns e164 formatted phone number. Method can receive single string parameter that will be defined as prefix
Returns e164 formatted phone number . Method can receive single string parameter that will be defined as prefix
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 valid?
      return "#{prefix}#{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}#{country_code} #{national}"
    end
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 valid? return "#{prefix}#{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}#{country_code} #{national}" end
Returns e164 formatted phone number.
Returns e164 formatted phone number .
formatted international number
formatted international number
String
formatted
whether to return numbers only or formatted
whether to return numbers only or formatted
prefix
prefix to be placed before the number, "+" by default
prefix to be placed before the number " + " by default