Class: Worldwide::Phone
- Inherits:
-
Object
- Object
- Worldwide::Phone
- Defined in:
- lib/worldwide/phone.rb
Class Attribute Summary collapse
-
.shared_codes_cache ⇒ Object
Returns the value of attribute shared_codes_cache.
Instance Attribute Summary collapse
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
Instance Method Summary collapse
-
#country_code ⇒ Object
Return the ISO-3166 alpha-2 code of the country in which this phone number is located.
-
#country_prefix ⇒ Object
Returns the country prefix for the phone number.
-
#domestic ⇒ Object
Return a formatted number suitable for domestic dialing in the specified country.
-
#e164 ⇒ Object
Return the number in E.164 international format.
-
#initialize(number:, country_code: nil) ⇒ Phone
constructor
A new instance of Phone.
-
#international ⇒ Object
Return a formatted number including the international country code.
-
#raw ⇒ Object
Return the raw "number" string that was specified when creating this Phone object.
- #valid? ⇒ Boolean
Constructor Details
#initialize(number:, country_code: nil) ⇒ Phone
Returns a new instance of Phone.
16 17 18 19 |
# File 'lib/worldwide/phone.rb', line 16 def initialize(number:, country_code: nil) @number = number @parsed_number, @extension, @country_code = parse_number(number: @number, country_code: country_code) end |
Class Attribute Details
.shared_codes_cache ⇒ Object
Returns the value of attribute shared_codes_cache.
11 12 13 |
# File 'lib/worldwide/phone.rb', line 11 def shared_codes_cache @shared_codes_cache end |
Instance Attribute Details
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
14 15 16 |
# File 'lib/worldwide/phone.rb', line 14 def extension @extension end |
Instance Method Details
#country_code ⇒ Object
Return the ISO-3166 alpha-2 code of the country in which this phone number is located
22 23 24 |
# File 'lib/worldwide/phone.rb', line 22 def country_code @parsed_number.country end |
#country_prefix ⇒ Object
Returns the country prefix for the phone number
51 52 53 |
# File 'lib/worldwide/phone.rb', line 51 def country_prefix @parsed_number.country_code end |
#domestic ⇒ Object
Return a formatted number suitable for domestic dialing in the specified country
27 28 29 |
# File 'lib/worldwide/phone.rb', line 27 def domestic @parsed_number.national end |
#e164 ⇒ Object
Return the number in E.164 international format
32 33 34 |
# File 'lib/worldwide/phone.rb', line 32 def e164 @parsed_number.e164 end |
#international ⇒ Object
Return a formatted number including the international country code
37 38 39 |
# File 'lib/worldwide/phone.rb', line 37 def international @parsed_number.international end |
#raw ⇒ Object
Return the raw "number" string that was specified when creating this Phone object
42 43 44 |
# File 'lib/worldwide/phone.rb', line 42 def raw @number end |
#valid? ⇒ Boolean
46 47 48 |
# File 'lib/worldwide/phone.rb', line 46 def valid? @parsed_number.valid? end |