Class: TelephoneNumber::Formatter
- Inherits:
-
Object
- Object
- TelephoneNumber::Formatter
- Defined in:
- lib/telephone_number/formatter.rb
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#normalized_number ⇒ Object
readonly
Returns the value of attribute normalized_number.
-
#original_number ⇒ Object
readonly
Returns the value of attribute original_number.
-
#valid ⇒ Object
(also: #valid?)
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #e164_number(formatted: true) ⇒ Object
-
#initialize(number_obj) ⇒ Formatter
constructor
A new instance of Formatter.
- #international_number(formatted: true) ⇒ Object
- #national_number(formatted: true) ⇒ Object
Constructor Details
#initialize(number_obj) ⇒ Formatter
Returns a new instance of Formatter.
6 7 8 9 10 11 |
# File 'lib/telephone_number/formatter.rb', line 6 def initialize(number_obj) @normalized_number = number_obj.normalized_number @country = number_obj.country @valid = number_obj.valid? @original_number = number_obj.original_number end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
4 5 6 |
# File 'lib/telephone_number/formatter.rb', line 4 def country @country end |
#normalized_number ⇒ Object (readonly)
Returns the value of attribute normalized_number.
4 5 6 |
# File 'lib/telephone_number/formatter.rb', line 4 def normalized_number @normalized_number end |
#original_number ⇒ Object (readonly)
Returns the value of attribute original_number.
4 5 6 |
# File 'lib/telephone_number/formatter.rb', line 4 def original_number @original_number end |
#valid ⇒ Object (readonly) Also known as: valid?
Returns the value of attribute valid.
4 5 6 |
# File 'lib/telephone_number/formatter.rb', line 4 def valid @valid end |
Instance Method Details
#e164_number(formatted: true) ⇒ Object
18 19 20 21 |
# File 'lib/telephone_number/formatter.rb', line 18 def e164_number(formatted: true) return original_or_default if !valid? build_e164_number(formatted: formatted) end |
#international_number(formatted: true) ⇒ Object
23 24 25 26 |
# File 'lib/telephone_number/formatter.rb', line 23 def international_number(formatted: true) return original_or_default if !valid? || !number_format build_international_number(formatted: formatted) end |
#national_number(formatted: true) ⇒ Object
13 14 15 16 |
# File 'lib/telephone_number/formatter.rb', line 13 def national_number(formatted: true) return original_or_default if !valid? || !number_format build_national_number(formatted: formatted) end |