Class: PicoPhone::PhoneNumber
- Inherits:
-
Object
- Object
- PicoPhone::PhoneNumber
- Defined in:
- lib/pico_phone/phone_number.rb
Instance Method Summary collapse
-
#area_code ⇒ String
Geographic area code digits, or empty string if none.
-
#can_be_internationally_dialled? ⇒ Boolean
False for numbers that only work within their own country.
-
#carrier_name(language = "en") ⇒ String
Name of the carrier the number was originally allocated to.
-
#country ⇒ String
ISO 3166-1 alpha-2 region code (e.g. "US").
-
#country_code ⇒ Integer
E.g.
-
#e164 ⇒ String
E.g.
- #extension ⇒ String?
-
#format_in_original_format ⇒ String
Format using the same style (international vs. national) as the original input.
-
#full_e164 ⇒ String
E.164 format with extension appended using the configured prefix.
-
#full_international ⇒ String
International format with extension appended using the configured prefix.
-
#full_national ⇒ String
National format with extension appended using the configured prefix.
-
#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.
-
#geographical? ⇒ Boolean
True for fixed-line numbers tied to a geographic area code.
- #has_extension? ⇒ Boolean
- #impossible? ⇒ Boolean
-
#initialize(string, region = nil) ⇒ PhoneNumber
constructor
A new instance of PhoneNumber.
-
#international ⇒ String
E.g.
- #invalid? ⇒ Boolean
- #invalid_for_country?(region) ⇒ Boolean
-
#local_number ⇒ String
Subscriber number after the area code.
-
#match_type(other) ⇒ Symbol
Compare this number against another and return how closely they match.
-
#mobile_dialing_format(region) ⇒ String
Format the number for convenient dialing on a mobile device in the given region.
-
#national ⇒ String
E.g.
-
#original ⇒ String?
The raw input string as passed to the constructor.
-
#out_of_country_format(region) ⇒ String
Format the number as it would be dialed from outside its home country.
- #possible? ⇒ Boolean
-
#possible_countries ⇒ Array<String>
Regions that could own this number based on length (unambiguous codes) or pattern (shared calling codes like +1 or +7).
-
#possible_for_type?(type) ⇒ Boolean
True when the number's digit count is consistent with the given type in its region.
-
#possible_with_reason ⇒ Symbol
Why the number is or is not possible.
-
#raw_international ⇒ String
International number digits with calling code, no formatting punctuation.
-
#raw_national ⇒ String
National significant number as plain digits, no formatting punctuation.
-
#timezones ⇒ Array<String>
IANA time zone names the number's prefix belongs to.
-
#to_s ⇒ String
E.164 for a valid number; falls back to #original for an invalid one.
-
#truncate ⇒ PhoneNumber?
Removes trailing digits until the number is valid, returning the truncated number as a new PhoneNumber.
-
#type ⇒ Symbol
:fixed_line, :mobile, :fixed_line_or_mobile, :toll_free, :premium_rate, :shared_cost, :voip, :personal_number, :pager, :uan, :voicemail, or :unknown.
- #valid? ⇒ Boolean
-
#valid_countries ⇒ Array<String>
Regions for which this number passes strict pattern validation.
- #valid_for_country?(region) ⇒ Boolean
Constructor Details
#initialize(string, region = nil) ⇒ PhoneNumber
Returns a new instance of PhoneNumber.
125 |
# File 'lib/pico_phone/phone_number.rb', line 125 def initialize(string, region = nil); end |
Instance Method Details
#area_code ⇒ String
Returns 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.
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.
214 |
# File 'lib/pico_phone/phone_number.rb', line 214 def carrier_name(language = "en"); end |
#country ⇒ String
Returns ISO 3166-1 alpha-2 region code (e.g. "US").
175 |
# File 'lib/pico_phone/phone_number.rb', line 175 def country; end |
#country_code ⇒ Integer
Returns e.g. 1 for US/CA, 61 for AU.
172 |
# File 'lib/pico_phone/phone_number.rb', line 172 def country_code; end |
#e164 ⇒ String
Returns e.g. "+15102745656".
151 |
# File 'lib/pico_phone/phone_number.rb', line 151 def e164; end |
#extension ⇒ String?
154 |
# File 'lib/pico_phone/phone_number.rb', line 154 def extension; end |
#format_in_original_format ⇒ String
Format using the same style (international vs. national) as the original input.
244 |
# File 'lib/pico_phone/phone_number.rb', line 244 def format_in_original_format; end |
#full_e164 ⇒ String
E.164 format with extension appended using the configured prefix.
169 |
# File 'lib/pico_phone/phone_number.rb', line 169 def full_e164; end |
#full_international ⇒ String
International format with extension appended using the configured prefix.
165 |
# File 'lib/pico_phone/phone_number.rb', line 165 def full_international; end |
#full_national ⇒ String
National format with extension appended using the configured prefix.
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.
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.
267 |
# File 'lib/pico_phone/phone_number.rb', line 267 def geographical?; end |
#has_extension? ⇒ Boolean
157 |
# File 'lib/pico_phone/phone_number.rb', line 157 def has_extension?; end |
#impossible? ⇒ Boolean
137 |
# File 'lib/pico_phone/phone_number.rb', line 137 def impossible?; end |
#international ⇒ String
Returns e.g. "+1 510-274-5656".
148 |
# File 'lib/pico_phone/phone_number.rb', line 148 def international; end |
#invalid? ⇒ Boolean
131 |
# File 'lib/pico_phone/phone_number.rb', line 131 def invalid?; end |
#invalid_for_country?(region) ⇒ Boolean
231 |
# File 'lib/pico_phone/phone_number.rb', line 231 def invalid_for_country?(region); end |
#local_number ⇒ String
Subscriber number after the area code. Returns the full national number when there is no geographic area code (e.g. mobile numbers in AU).
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.
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.
254 |
# File 'lib/pico_phone/phone_number.rb', line 254 def mobile_dialing_format(region); end |
#national ⇒ String
Returns e.g. "(510) 274-5656".
145 |
# File 'lib/pico_phone/phone_number.rb', line 145 def national; end |
#original ⇒ String?
The raw input string as passed to the constructor. Survives a failed parse.
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.
249 |
# File 'lib/pico_phone/phone_number.rb', line 249 def out_of_country_format(region); end |
#possible? ⇒ Boolean
134 |
# File 'lib/pico_phone/phone_number.rb', line 134 def possible?; end |
#possible_countries ⇒ Array<String>
Regions that could own this number based on length (unambiguous codes) or pattern (shared calling codes like +1 or +7).
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.
282 |
# File 'lib/pico_phone/phone_number.rb', line 282 def possible_for_type?(type); end |
#possible_with_reason ⇒ Symbol
Why the number is or is not possible.
142 |
# File 'lib/pico_phone/phone_number.rb', line 142 def possible_with_reason; end |
#raw_international ⇒ String
International number digits with calling code, no formatting punctuation.
186 |
# File 'lib/pico_phone/phone_number.rb', line 186 def raw_international; end |
#raw_national ⇒ String
National significant number as plain digits, no formatting punctuation.
182 |
# File 'lib/pico_phone/phone_number.rb', line 182 def raw_national; end |
#timezones ⇒ Array<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.
223 |
# File 'lib/pico_phone/phone_number.rb', line 223 def timezones; end |
#to_s ⇒ String
E.164 for a valid number; falls back to #original for an invalid one. Returns an empty string when nil was passed as input.
240 |
# File 'lib/pico_phone/phone_number.rb', line 240 def to_s; end |
#truncate ⇒ PhoneNumber?
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.
292 |
# File 'lib/pico_phone/phone_number.rb', line 292 def truncate; end |
#type ⇒ Symbol
Returns :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
128 |
# File 'lib/pico_phone/phone_number.rb', line 128 def valid?; end |
#valid_countries ⇒ Array<String>
Regions for which this number passes strict pattern validation.
263 |
# File 'lib/pico_phone/phone_number.rb', line 263 def valid_countries; end |
#valid_for_country?(region) ⇒ Boolean
227 |
# File 'lib/pico_phone/phone_number.rb', line 227 def valid_for_country?(region); end |