Class: PicoPhone::PhoneNumber

Inherits:
Object
  • Object
show all
Defined in:
lib/pico_phone/phone_number.rb

Instance Method Summary collapse

Constructor Details

#initialize(string, region = nil) ⇒ PhoneNumber

Returns a new instance of PhoneNumber.

Parameters:

  • string (String, nil)

    raw phone number input

  • region (String, nil) (defaults to: nil)

    ISO 3166-1 alpha-2 region hint (e.g. "US")



125
# File 'lib/pico_phone/phone_number.rb', line 125

def initialize(string, region = nil); end

Instance Method Details

#area_codeString

Returns geographic area code digits, or empty string if none.

Returns:

  • (String)

    geographic area code digits, or empty string if none



178
# File 'lib/pico_phone/phone_number.rb', line 178

def area_code; end

#can_be_internationally_dialled?Boolean

False for numbers that only work within their own country.

Returns:

  • (Boolean)


286
# File 'lib/pico_phone/phone_number.rb', line 286

def can_be_internationally_dialled?; end

#carrier_name(language = "en") ⇒ String

Name of the carrier the number was originally allocated to. In countries that support mobile number portability, the number may no longer actually belong to this carrier -- this is the carrier at allocation time, not necessarily the current one. Returns an empty string when no carrier mapping exists for the prefix, or for numbers that could not be parsed.

Parameters:

  • language (String) (defaults to: "en")

    two- or three-letter ISO 639 language code (default: "en")

Returns:

  • (String)


214
# File 'lib/pico_phone/phone_number.rb', line 214

def carrier_name(language = "en"); end

#countryString

Returns ISO 3166-1 alpha-2 region code (e.g. "US").

Returns:

  • (String)

    ISO 3166-1 alpha-2 region code (e.g. "US")



175
# File 'lib/pico_phone/phone_number.rb', line 175

def country; end

#country_codeInteger

Returns e.g. 1 for US/CA, 61 for AU.

Returns:

  • (Integer)

    e.g. 1 for US/CA, 61 for AU



172
# File 'lib/pico_phone/phone_number.rb', line 172

def country_code; end

#e164String

Returns e.g. "+15102745656".

Returns:

  • (String)

    e.g. "+15102745656"



151
# File 'lib/pico_phone/phone_number.rb', line 151

def e164; end

#extensionString?

Returns:

  • (String, nil)


154
# File 'lib/pico_phone/phone_number.rb', line 154

def extension; end

#format_in_original_formatString

Format using the same style (international vs. national) as the original input.

Returns:

  • (String)


244
# File 'lib/pico_phone/phone_number.rb', line 244

def format_in_original_format; end

#full_e164String

E.164 format with extension appended using the configured prefix.

Returns:

  • (String)


169
# File 'lib/pico_phone/phone_number.rb', line 169

def full_e164; end

#full_internationalString

International format with extension appended using the configured prefix.

Returns:

  • (String)


165
# File 'lib/pico_phone/phone_number.rb', line 165

def full_international; end

#full_nationalString

National format with extension appended using the configured prefix.

Returns:

  • (String)


161
# File 'lib/pico_phone/phone_number.rb', line 161

def full_national; end

#geo_name(language = "en") ⇒ String

Text description of the geographic area the number is from (e.g. a city or region), falling back to the country name when no finer-grained description is available. Returns an empty string for non-geographical numbers (e.g. toll-free) or numbers that could not be parsed.

Parameters:

  • language (String) (defaults to: "en")

    two- or three-letter ISO 639 language code (default: "en")

Returns:

  • (String)


204
# File 'lib/pico_phone/phone_number.rb', line 204

def geo_name(language = "en"); end

#geographical?Boolean

True for fixed-line numbers tied to a geographic area code.

Returns:

  • (Boolean)


267
# File 'lib/pico_phone/phone_number.rb', line 267

def geographical?; end

#has_extension?Boolean

Returns:

  • (Boolean)


157
# File 'lib/pico_phone/phone_number.rb', line 157

def has_extension?; end

#impossible?Boolean

Returns:

  • (Boolean)


137
# File 'lib/pico_phone/phone_number.rb', line 137

def impossible?; end

#internationalString

Returns e.g. "+1 510-274-5656".

Returns:

  • (String)

    e.g. "+1 510-274-5656"



148
# File 'lib/pico_phone/phone_number.rb', line 148

def international; end

#invalid?Boolean

Returns:

  • (Boolean)


131
# File 'lib/pico_phone/phone_number.rb', line 131

def invalid?; end

#invalid_for_country?(region) ⇒ Boolean

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


231
# File 'lib/pico_phone/phone_number.rb', line 231

def invalid_for_country?(region); end

#local_numberString

Subscriber number after the area code. Returns the full national number when there is no geographic area code (e.g. mobile numbers in AU).

Returns:

  • (String)


196
# File 'lib/pico_phone/phone_number.rb', line 196

def local_number; end

#match_type(other) ⇒ Symbol

Compare this number against another and return how closely they match. Pass a String or a PhoneNumber. When passed a PhoneNumber, the country code stored in the proto is used for comparison, giving more precise results than a bare national-format string.

Parameters:

Returns:

  • (Symbol)

    :exact_match, :nsn_match, :short_nsn_match, :no_match, or :invalid_number



275
# File 'lib/pico_phone/phone_number.rb', line 275

def match_type(other); end

#mobile_dialing_format(region) ⇒ String

Format the number for convenient dialing on a mobile device in the given region.

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region of the caller

Returns:

  • (String)


254
# File 'lib/pico_phone/phone_number.rb', line 254

def mobile_dialing_format(region); end

#nationalString

Returns e.g. "(510) 274-5656".

Returns:

  • (String)

    e.g. "(510) 274-5656"



145
# File 'lib/pico_phone/phone_number.rb', line 145

def national; end

#originalString?

The raw input string as passed to the constructor. Survives a failed parse.

Returns:

  • (String, nil)


235
# File 'lib/pico_phone/phone_number.rb', line 235

def original; end

#out_of_country_format(region) ⇒ String

Format the number as it would be dialed from outside its home country.

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region of the caller

Returns:

  • (String)


249
# File 'lib/pico_phone/phone_number.rb', line 249

def out_of_country_format(region); end

#possible?Boolean

Returns:

  • (Boolean)


134
# File 'lib/pico_phone/phone_number.rb', line 134

def possible?; end

#possible_countriesArray<String>

Regions that could own this number based on length (unambiguous codes) or pattern (shared calling codes like +1 or +7).

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 region codes



259
# File 'lib/pico_phone/phone_number.rb', line 259

def possible_countries; end

#possible_for_type?(type) ⇒ Boolean

True when the number's digit count is consistent with the given type in its region. More permissive than #type: a 10-digit US number is possible for both :fixed_line_or_mobile and :toll_free since they share the same digit count.

Parameters:

  • type (Symbol)

    e.g. :mobile, :toll_free, :fixed_line

Returns:

  • (Boolean)


282
# File 'lib/pico_phone/phone_number.rb', line 282

def possible_for_type?(type); end

#possible_with_reasonSymbol

Why the number is or is not possible.

Returns:

  • (Symbol)

    :is_possible, :is_possible_local_only, :too_short, :too_long, :invalid_country_code, or :invalid_length



142
# File 'lib/pico_phone/phone_number.rb', line 142

def possible_with_reason; end

#raw_internationalString

International number digits with calling code, no formatting punctuation.

Returns:

  • (String)


186
# File 'lib/pico_phone/phone_number.rb', line 186

def raw_international; end

#raw_nationalString

National significant number as plain digits, no formatting punctuation.

Returns:

  • (String)


182
# File 'lib/pico_phone/phone_number.rb', line 182

def raw_national; end

#timezonesArray<String>

IANA time zone names the number's prefix belongs to. A single prefix can map to several zones (e.g. NANPA numbers span many), hence the plural. Time zone identifiers aren't translated, so unlike geo_name and carrier_name there's no language parameter. Returns an empty array when no mapping exists for the prefix, or for numbers that could not be parsed.

Returns:

  • (Array<String>)


223
# File 'lib/pico_phone/phone_number.rb', line 223

def timezones; end

#to_sString

E.164 for a valid number; falls back to #original for an invalid one. Returns an empty string when nil was passed as input.

Returns:

  • (String)


240
# File 'lib/pico_phone/phone_number.rb', line 240

def to_s; end

#truncatePhoneNumber?

Removes trailing digits until the number is valid, returning the truncated number as a new PhoneNumber. Returns nil if the number was not too long or if no valid truncation exists. Does not mutate the receiver.

Returns:



292
# File 'lib/pico_phone/phone_number.rb', line 292

def truncate; end

#typeSymbol

Returns :fixed_line, :mobile, :fixed_line_or_mobile, :toll_free, :premium_rate, :shared_cost, :voip, :personal_number, :pager, :uan, :voicemail, or :unknown.

Returns:

  • (Symbol)

    :fixed_line, :mobile, :fixed_line_or_mobile, :toll_free, :premium_rate, :shared_cost, :voip, :personal_number, :pager, :uan, :voicemail, or :unknown



191
# File 'lib/pico_phone/phone_number.rb', line 191

def type; end

#valid?Boolean

Returns:

  • (Boolean)


128
# File 'lib/pico_phone/phone_number.rb', line 128

def valid?; end

#valid_countriesArray<String>

Regions for which this number passes strict pattern validation.

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 region codes



263
# File 'lib/pico_phone/phone_number.rb', line 263

def valid_countries; end

#valid_for_country?(region) ⇒ Boolean

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


227
# File 'lib/pico_phone/phone_number.rb', line 227

def valid_for_country?(region); end