Class: TelephoneNumber::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number_obj) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
# File 'lib/telephone_number/parser.rb', line 5

def initialize(number_obj)
  @original_number = number_obj.original_number
  @country = number_obj.country
  @normalized_number = build_normalized_number if @country
end

Instance Attribute Details

#countryObject (readonly)

Returns the value of attribute country.



3
4
5
# File 'lib/telephone_number/parser.rb', line 3

def country
  @country
end

#normalized_numberObject (readonly)

Returns the value of attribute normalized_number.



3
4
5
# File 'lib/telephone_number/parser.rb', line 3

def normalized_number
  @normalized_number
end

#original_numberObject (readonly)

Returns the value of attribute original_number.



3
4
5
# File 'lib/telephone_number/parser.rb', line 3

def original_number
  @original_number
end

Instance Method Details

#valid?(keys = []) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/telephone_number/parser.rb', line 15

def valid?(keys = [])
  keys.empty? ? !valid_types.empty? : !(valid_types & keys.map(&:to_sym)).empty?
end

#valid_typesObject



11
12
13
# File 'lib/telephone_number/parser.rb', line 11

def valid_types
  @valid_types ||= generate_valid_types(normalized_number)
end