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.
-
#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 20 |
# File 'lib/worldwide/phone.rb', line 16 def initialize(number:, country_code: nil) @number = number @country_code = country_code&.to_s&.downcase&.to_sym @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
23 24 25 |
# File 'lib/worldwide/phone.rb', line 23 def country_code @parsed_number.country end |
#domestic ⇒ Object
Return a formatted number suitable for domestic dialing in the specified country
28 29 30 |
# File 'lib/worldwide/phone.rb', line 28 def domestic @parsed_number.national end |
#e164 ⇒ Object
Return the number in E.164 international format
33 34 35 |
# File 'lib/worldwide/phone.rb', line 33 def e164 @parsed_number.e164 end |
#international ⇒ Object
Return a formatted number including the international country code
38 39 40 |
# File 'lib/worldwide/phone.rb', line 38 def international @parsed_number.international end |
#raw ⇒ Object
Return the raw “number” string that was specified when creating this Phone object
43 44 45 |
# File 'lib/worldwide/phone.rb', line 43 def raw @number end |
#valid? ⇒ Boolean
47 48 49 |
# File 'lib/worldwide/phone.rb', line 47 def valid? @parsed_number.valid? end |