Class: TelephoneNumber::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/telephone_number/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_obj) ⇒ Formatter

Returns a new instance of Formatter.



6
7
8
9
10
11
# File 'lib/telephone_number/formatter.rb', line 6

def initialize(number_obj)
  @normalized_number = number_obj.normalized_number
  @country = number_obj.country
  @valid = number_obj.valid?
  @original_number = number_obj.original_number
end

Instance Attribute Details

#countryObject (readonly)

Returns the value of attribute country.



4
5
6
# File 'lib/telephone_number/formatter.rb', line 4

def country
  @country
end

#normalized_numberObject (readonly)

Returns the value of attribute normalized_number.



4
5
6
# File 'lib/telephone_number/formatter.rb', line 4

def normalized_number
  @normalized_number
end

#original_numberObject (readonly)

Returns the value of attribute original_number.



4
5
6
# File 'lib/telephone_number/formatter.rb', line 4

def original_number
  @original_number
end

#validObject (readonly) Also known as: valid?

Returns the value of attribute valid.



4
5
6
# File 'lib/telephone_number/formatter.rb', line 4

def valid
  @valid
end

Instance Method Details

#e164_number(formatted: true) ⇒ Object



18
19
20
21
# File 'lib/telephone_number/formatter.rb', line 18

def e164_number(formatted: true)
  return original_or_default if !valid?
  build_e164_number(formatted: formatted)
end

#international_number(formatted: true) ⇒ Object



23
24
25
26
# File 'lib/telephone_number/formatter.rb', line 23

def international_number(formatted: true)
  return original_or_default if !valid? || !number_format
  build_international_number(formatted: formatted)
end

#national_number(formatted: true) ⇒ Object



13
14
15
16
# File 'lib/telephone_number/formatter.rb', line 13

def national_number(formatted: true)
  return original_or_default if !valid? || !number_format
  build_national_number(formatted: formatted)
end