Class: Phones::Phone
- Inherits:
-
Object
- Object
- Phones::Phone
- Defined in:
- lib/phones/phone.rb
Constant Summary collapse
- RESTRICTED_CHARACTERS =
/\-|\(|\)|\.|\s|[a-zA-Z]/.freeze
Instance Attribute Summary collapse
-
#area_code ⇒ Object
Returns the value of attribute area_code.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#local_code ⇒ Object
Returns the value of attribute local_code.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Phone
constructor
A new instance of Phone.
- #pretty ⇒ Object
- #to_phone ⇒ Object
- #to_s ⇒ Object
- #united_states? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Phone
6 7 8 9 10 |
# File 'lib/phones/phone.rb', line 6 def initialize(opts = {}) self.country_code = opts[:country_code] self.area_code = opts[:area_code] self.local_code = opts[:local_code] end |
Instance Attribute Details
#area_code ⇒ Object
Returns the value of attribute area_code.
4 5 6 |
# File 'lib/phones/phone.rb', line 4 def area_code @area_code end |
#country_code ⇒ Object
Returns the value of attribute country_code.
4 5 6 |
# File 'lib/phones/phone.rb', line 4 def country_code @country_code end |
#local_code ⇒ Object
Returns the value of attribute local_code.
4 5 6 |
# File 'lib/phones/phone.rb', line 4 def local_code @local_code end |
Instance Method Details
#pretty ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/phones/phone.rb', line 31 def pretty if self.united_states? "(#{self.area_code}) #{self.local_code[0..2]}-#{self.local_code[3..-1]}" else self.to_s end end |
#to_phone ⇒ Object
43 44 45 |
# File 'lib/phones/phone.rb', line 43 def to_phone self end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/phones/phone.rb', line 39 def to_s "#{self.country_code}#{self.area_code}#{self.local_code}" end |
#united_states? ⇒ Boolean
47 48 49 |
# File 'lib/phones/phone.rb', line 47 def united_states? self.country_code == "+1" end |