Class: IdNumberLatam::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/id_number_latam/base.rb

Direct Known Subclasses

ArDni, ClDni, EcDni, PeDni, PyDni, UyDni

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id_number, opts = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/id_number_latam/base.rb', line 12

def initialize(id_number, opts = {})
  @id_number = id_number
  @country   = opts.delete(:country)&.to_sym
  @dni_class = get_dni_class.new(@id_number) if @country
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



10
11
12
# File 'lib/id_number_latam/base.rb', line 10

def country
  @country
end

#id_numberObject

Returns the value of attribute id_number.



10
11
12
# File 'lib/id_number_latam/base.rb', line 10

def id_number
  @id_number
end

#unformatted_id_numberObject

Returns the value of attribute unformatted_id_number.



10
11
12
# File 'lib/id_number_latam/base.rb', line 10

def unformatted_id_number
  @unformatted_id_number
end

Instance Method Details

#get_dni_classObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/id_number_latam/base.rb', line 18

def get_dni_class
  return unless @country

  country_dni_class = IdNumberLatam.constants.map(&:to_s).detect { |c| c == "#{@country.capitalize}Dni" }
  unless country_dni_class
    raise "class IdNumberLatam::#{@country.capitalize}Dni not implemented for #{@country} country code"
  end

  IdNumberLatam.const_get country_dni_class
end