Class: Fakie::PhoneNumber
- Inherits:
-
Object
- Object
- Fakie::PhoneNumber
- Defined in:
- lib/fakie/phone_number.rb
Instance Attribute Summary collapse
-
#area_code ⇒ Object
readonly
Returns the value of attribute area_code.
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#country_code_source ⇒ Object
readonly
Returns the value of attribute country_code_source.
-
#e164 ⇒ Object
readonly
Returns the value of attribute e164.
-
#national_number ⇒ Object
readonly
Returns the value of attribute national_number.
-
#preferred_domestic_carrier_code ⇒ Object
readonly
Returns the value of attribute preferred_domestic_carrier_code.
-
#raw_input ⇒ Object
readonly
Returns the value of attribute raw_input.
-
#region_code ⇒ Object
readonly
Returns the value of attribute region_code.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.parse(phone_number, options = {}) ⇒ PhoneNumber
Parse a phone number.
Instance Method Summary collapse
- #country_name ⇒ Object
-
#initialize(hash) ⇒ PhoneNumber
constructor
A new instance of PhoneNumber.
- #international_format(region = self.region_code) ⇒ Object
- #is_possible? ⇒ Boolean
- #is_valid? ⇒ Boolean
- #local_format(region = self.region_code) ⇒ Object
Constructor Details
#initialize(hash) ⇒ PhoneNumber
Returns a new instance of PhoneNumber.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fakie/phone_number.rb', line 25 def initialize(hash) @e164 = hash['e164'] @country_code = hash['country_code'] @national_number = hash['national_number'] @area_code = hash['area_code'] @raw_input = hash['raw_input'].to_s @country_code_source = hash['country_code_source'] @preferred_domestic_carrier_code = hash['preferred_domestic_carrier_code'] @is_possible = hash['is_possible'] @is_valid = hash['is_valid'] @region_code = hash['region'] @type = hash['type'] end |
Instance Attribute Details
#area_code ⇒ Object (readonly)
Returns the value of attribute area_code.
17 18 19 |
# File 'lib/fakie/phone_number.rb', line 17 def area_code @area_code end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
15 16 17 |
# File 'lib/fakie/phone_number.rb', line 15 def country_code @country_code end |
#country_code_source ⇒ Object (readonly)
Returns the value of attribute country_code_source.
19 20 21 |
# File 'lib/fakie/phone_number.rb', line 19 def country_code_source @country_code_source end |
#e164 ⇒ Object (readonly)
Returns the value of attribute e164.
14 15 16 |
# File 'lib/fakie/phone_number.rb', line 14 def e164 @e164 end |
#national_number ⇒ Object (readonly)
Returns the value of attribute national_number.
16 17 18 |
# File 'lib/fakie/phone_number.rb', line 16 def national_number @national_number end |
#preferred_domestic_carrier_code ⇒ Object (readonly)
Returns the value of attribute preferred_domestic_carrier_code.
20 21 22 |
# File 'lib/fakie/phone_number.rb', line 20 def preferred_domestic_carrier_code @preferred_domestic_carrier_code end |
#raw_input ⇒ Object (readonly)
Returns the value of attribute raw_input.
18 19 20 |
# File 'lib/fakie/phone_number.rb', line 18 def raw_input @raw_input end |
#region_code ⇒ Object (readonly)
Returns the value of attribute region_code.
21 22 23 |
# File 'lib/fakie/phone_number.rb', line 21 def region_code @region_code end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/fakie/phone_number.rb', line 22 def type @type end |
Class Method Details
.parse(phone_number, options = {}) ⇒ PhoneNumber
Parse a phone number
8 9 10 11 |
# File 'lib/fakie/phone_number.rb', line 8 def parse(phone_number, = {}) region_code = [:default_country] self.new(JavaScript.call('Fakie.parse', phone_number, region_code)) end |
Instance Method Details
#country_name ⇒ Object
57 58 59 60 |
# File 'lib/fakie/phone_number.rb', line 57 def country_name return nil unless self.region_code Fakie.country_name_for_region_code(self.region_code) end |
#international_format(region = self.region_code) ⇒ Object
47 48 49 50 |
# File 'lib/fakie/phone_number.rb', line 47 def international_format(region = self.region_code) raise InvalidPhoneNumber unless self.is_valid? @international_format ||= JavaScript.call('Fakie.formatInternational', region, self.e164) end |
#is_possible? ⇒ Boolean
39 40 41 |
# File 'lib/fakie/phone_number.rb', line 39 def is_possible? @is_possible end |
#is_valid? ⇒ Boolean
43 44 45 |
# File 'lib/fakie/phone_number.rb', line 43 def is_valid? @is_valid end |
#local_format(region = self.region_code) ⇒ Object
52 53 54 55 |
# File 'lib/fakie/phone_number.rb', line 52 def local_format(region = self.region_code) raise InvalidPhoneNumber unless self.is_valid? @local_format ||= JavaScript.call('Fakie.formatLocal', region, self.e164) end |