Class: Worldwide::Phone

Inherits:
Object
  • Object
show all
Defined in:
lib/worldwide/phone.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, country_code: nil) ⇒ Phone

Returns a new instance of Phone.



16
17
18
19
20
# File 'lib/worldwide/phone.rb', line 16

def initialize(number:, country_code: nil)
  @number = number
  @country_code = country_code&.to_s&.downcase&.to_sym
  @parsed_number, @extension, @country_code = parse_number(number: @number, country_code: country_code)
end

Class Attribute Details

.shared_codes_cacheObject

Returns the value of attribute shared_codes_cache.



11
12
13
# File 'lib/worldwide/phone.rb', line 11

def shared_codes_cache
  @shared_codes_cache
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension.



14
15
16
# File 'lib/worldwide/phone.rb', line 14

def extension
  @extension
end

Instance Method Details

#country_codeObject

Return the ISO-3166 alpha-2 code of the country in which this phone number is located



23
24
25
# File 'lib/worldwide/phone.rb', line 23

def country_code
  @parsed_number.country
end

#domesticObject

Return a formatted number suitable for domestic dialing in the specified country



28
29
30
# File 'lib/worldwide/phone.rb', line 28

def domestic
  @parsed_number.national
end

#e164Object

Return the number in E.164 international format



33
34
35
# File 'lib/worldwide/phone.rb', line 33

def e164
  @parsed_number.e164
end

#internationalObject

Return a formatted number including the international country code



38
39
40
# File 'lib/worldwide/phone.rb', line 38

def international
  @parsed_number.international
end

#rawObject

Return the raw “number” string that was specified when creating this Phone object



43
44
45
# File 'lib/worldwide/phone.rb', line 43

def raw
  @number
end

#valid?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/worldwide/phone.rb', line 47

def valid?
  @parsed_number.valid?
end