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
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ PhoneNumber
Returns a new instance of PhoneNumber.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fakie/phone_number.rb', line 28 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.
20 21 22 |
# File 'lib/fakie/phone_number.rb', line 20 def area_code @area_code end |
#country_code ⇒ Object (readonly)
Returns the value of attribute country_code.
18 19 20 |
# File 'lib/fakie/phone_number.rb', line 18 def country_code @country_code end |
#country_code_source ⇒ Object (readonly)
Returns the value of attribute country_code_source.
22 23 24 |
# File 'lib/fakie/phone_number.rb', line 22 def country_code_source @country_code_source end |
#e164 ⇒ Object (readonly)
Returns the value of attribute e164.
17 18 19 |
# File 'lib/fakie/phone_number.rb', line 17 def e164 @e164 end |
#national_number ⇒ Object (readonly)
Returns the value of attribute national_number.
19 20 21 |
# File 'lib/fakie/phone_number.rb', line 19 def national_number @national_number end |
#preferred_domestic_carrier_code ⇒ Object (readonly)
Returns the value of attribute preferred_domestic_carrier_code.
23 24 25 |
# File 'lib/fakie/phone_number.rb', line 23 def preferred_domestic_carrier_code @preferred_domestic_carrier_code end |
#raw_input ⇒ Object (readonly)
Returns the value of attribute raw_input.
21 22 23 |
# File 'lib/fakie/phone_number.rb', line 21 def raw_input @raw_input end |
#region_code ⇒ Object (readonly)
Returns the value of attribute region_code.
24 25 26 |
# File 'lib/fakie/phone_number.rb', line 24 def region_code @region_code end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/fakie/phone_number.rb', line 25 def type @type end |
Class Method Details
.parse(phone_number, options = {}) ⇒ PhoneNumber
Parse a phone number
8 9 10 11 12 13 14 |
# File 'lib/fakie/phone_number.rb', line 8 def parse(phone_number, = {}) = Fakie..merge() region_code = [:default_country] self.new(JavaScript.call('Fakie.parse', phone_number, region_code)) rescue ExecJS::ProgramError => e self.new({'raw_input' => phone_number, 'is_valid' => false}) end |
Instance Method Details
#country_name ⇒ Object
68 69 70 71 |
# File 'lib/fakie/phone_number.rb', line 68 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
54 55 56 57 58 59 |
# File 'lib/fakie/phone_number.rb', line 54 def international_format(region = self.region_code) raise InvalidPhoneNumber, self.raw_input unless self.is_valid? @international_format ||= JavaScript.call('Fakie.formatInternational', region, self.e164) rescue ExecJS::ProgramError => e self.e164 end |
#is_possible? ⇒ Boolean
46 47 48 |
# File 'lib/fakie/phone_number.rb', line 46 def is_possible? @is_possible end |
#is_valid? ⇒ Boolean
50 51 52 |
# File 'lib/fakie/phone_number.rb', line 50 def is_valid? @is_valid end |
#local_format(region = self.region_code) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/fakie/phone_number.rb', line 61 def local_format(region = self.region_code) raise InvalidPhoneNumber, self.raw_input unless self.is_valid? @local_format ||= JavaScript.call('Fakie.formatLocal', region, self.e164) rescue ExecJS::ProgramError => e self.e164 end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/fakie/phone_number.rb', line 42 def to_s self.e164 end |