Module: PicoPhone

Defined in:
lib/pico_phone/phone_number.rb,
lib/pico_phone.rb,
lib/pico_phone/version.rb

Overview

Not loaded at runtime — exists only for YARD and IDE tooling. All methods are defined in ext/pico_phone/pico_phone.cpp via Rice.

Defined Under Namespace

Classes: Error, PhoneNumber, PhoneNumberMatch

Constant Summary collapse

VERSION =
"0.6.1"

Class Method Summary collapse

Class Method Details

.alpha_number?(string) ⇒ Boolean

Parameters:

  • string (String)

Returns:

  • (Boolean)


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

.convert_alpha_characters(string) ⇒ String

Convert vanity number alpha characters to digits (e.g. "1-800-FLOWERS" → "1-800-3569377").

Parameters:

  • string (String)

Returns:

  • (String)


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

.country_calling_code(region) ⇒ Integer

Returns the international calling code for a region. Returns 0 for unknown or invalid region codes.

Parameters:

  • region (String)

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

Returns:

  • (Integer)

    e.g. 1 for "US", 33 for "FR", 0 for unknown



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

.emergency_number?(string, region) ⇒ Boolean

Parameters:

  • string (String)
  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


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

.example_number(region) ⇒ PhoneNumber

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:



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

.example_number_for_type(region, type) ⇒ PhoneNumber

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region code

  • type (Symbol)

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

Returns:



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

.find_numbers(text, region, leniency: :valid) ⇒ Array<PhoneNumberMatch>

Scan a block of text and return every phone number found in it.

Parameters:

  • text (String)

    arbitrary text to search (must be valid UTF-8)

  • region (String)

    ISO 3166-1 alpha-2 default region for numbers without a country code

  • leniency (Symbol) (defaults to: :valid)

    :possible, :valid (default), :strict_grouping, or :exact_grouping

Returns:



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

.number_match(first, second) ⇒ Symbol

Compare two phone number strings and return how closely they match. Neither string requires a region hint; E.164 input gives the most precise result.

Parameters:

  • first (String)
  • second (String)

Returns:

  • (Symbol)

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



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

.parse(string, region = nil) ⇒ PhoneNumber

Parse a phone number string into a PhoneNumber object.

Parameters:

  • string (String)

    raw phone number input

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

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

Returns:



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

.possible?(string) ⇒ Boolean

Parameters:

  • string (String)

Returns:

  • (Boolean)


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

.possible_countries(string) ⇒ Array<String>

Regions that could own this number based on length or pattern.

Parameters:

  • string (String)

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 region codes



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

.possible_for_country?(string, region) ⇒ Boolean

Parameters:

  • string (String)
  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


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

.short_number_cost(string, region) ⇒ Symbol

Returns :toll_free, :standard_rate, :premium_rate, or :unknown_cost.

Parameters:

  • string (String)
  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Symbol)

    :toll_free, :standard_rate, :premium_rate, or :unknown_cost



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

.short_number_valid?(string, region) ⇒ Boolean

Parameters:

  • string (String)
  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


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

.supported_regionsArray<String>

All region codes the library knows about (~245 in libphonenumber 9.x).

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 region codes



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

.supported_types_for_region(region) ⇒ Array<Symbol>

Parameters:

  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Array<Symbol>)


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

.valid?(string) ⇒ Boolean

Parameters:

  • string (String)

Returns:

  • (Boolean)


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

.valid_countries(string) ⇒ Array<String>

Regions for which this number passes strict pattern validation.

Parameters:

  • string (String)

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 region codes



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

.valid_for_country?(string, region) ⇒ Boolean

Parameters:

  • string (String)
  • region (String)

    ISO 3166-1 alpha-2 region code

Returns:

  • (Boolean)


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