Class: Twilio::Rails::PhoneNumber
- Inherits:
-
Object
- Object
- Twilio::Rails::PhoneNumber
- Defined in:
- lib/twilio/rails/phone_number.rb
Overview
A phone number object that includes the country and some optional metadata.
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
-
#initialize(number:, country:, label: nil, project: nil) ⇒ PhoneNumber
constructor
A new instance of PhoneNumber.
-
#to_s ⇒ String
A human readable string representation of the phone number and its metadata.
Constructor Details
#initialize(number:, country:, label: nil, project: nil) ⇒ PhoneNumber
Returns a new instance of PhoneNumber.
12 13 14 15 16 17 18 |
# File 'lib/twilio/rails/phone_number.rb', line 12 def initialize(number:, country:, label: nil, project: nil) @number = Twilio::Rails::Formatter.coerce_to_valid_phone_number(number) raise Twilio::Rails::Phone::Error, "Invalid phone number '#{ number }'" unless @number @country = country&.upcase @label = label @project = project.presence&.to_s end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
6 7 8 |
# File 'lib/twilio/rails/phone_number.rb', line 6 def country @country end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'lib/twilio/rails/phone_number.rb', line 6 def label @label end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/twilio/rails/phone_number.rb', line 6 def number @number end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
6 7 8 |
# File 'lib/twilio/rails/phone_number.rb', line 6 def project @project end |
Instance Method Details
#to_s ⇒ String
Returns a human readable string representation of the phone number and its metadata.
21 22 23 24 25 26 |
# File 'lib/twilio/rails/phone_number.rb', line 21 def to_s s = "Phone number #{ number } (#{ country })" s = "#{ s } #{ label }" if label.present? s = "#{ s } for #{ project }" if project.present? s end |