Class: Sped2DB::Registro

Inherits:
Object
  • Object
show all
Defined in:
lib/sped2db/registro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(linha, metadados) ⇒ Registro

Returns a new instance of Registro.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sped2db/registro.rb', line 5

def initialize(linha, metadados)
  @linha = linha
  @metadados = metadados
  @valores = dividir_linha_em_valores linha
  @nome = @valores.shift.upcase

  validar_registro

  @pai = @metadados[@nome]['pai']
  @campos = @metadados[@nome]['campos']

  validar_campos

  corrigir_caracteres_especiais
  corrigir_datas

  @hash = to_h
end

Instance Attribute Details

#camposObject (readonly)

Returns the value of attribute campos.



3
4
5
# File 'lib/sped2db/registro.rb', line 3

def campos
  @campos
end

#nomeObject (readonly)

Returns the value of attribute nome.



3
4
5
# File 'lib/sped2db/registro.rb', line 3

def nome
  @nome
end

#paiObject (readonly)

Returns the value of attribute pai.



3
4
5
# File 'lib/sped2db/registro.rb', line 3

def pai
  @pai
end

#valoresObject (readonly)

Returns the value of attribute valores.



3
4
5
# File 'lib/sped2db/registro.rb', line 3

def valores
  @valores
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/sped2db/registro.rb', line 29

def [](key)
  @hash[key.to_sym]
end

#to_hObject



24
25
26
27
# File 'lib/sped2db/registro.rb', line 24

def to_h
  valores = @valores.map { |v| v.empty? ? nil : v }
  @campos.map(&:to_sym).zip(valores).to_h
end