class DfeTaxweb::Conjunto

Attributes

conjunto[R]
dados[RW]

Public Class Methods

new(hash) click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 8
def initialize(hash)
  @conjunto = hash.deep_symbolize_keys
  @dados = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 17
def [](key)
  conjunto[key]
end
atributo(path) click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 29
def atributo(path)
  valor = path.split(".").inject(conjunto) do |item, key|
    next if item.nil?
    if key =~ /\[\d+\]/
      item[key.sub(/\[\d+\]/, '').to_sym][key[/\[(\d+)\]/, 1].to_i]
    else
      item[key.to_sym]
    end
  end

  if valor.is_a?(Array)
    valor.map {|v| normaliza_valores(v)}.compact
  else
    normaliza_valores(valor)
  end
end
atualizar(hash) click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 46
def atualizar(hash)
  if hash.is_a?(Hash)
    conjunto.deep_merge!(hash.deep_symbolize_keys)
  end
  self
end
to_h() click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 13
def to_h
  conjunto
end

Private Instance Methods

normaliza_valores(valor) click to toggle source
# File lib/dfe_taxweb/conjunto.rb, line 54
def normaliza_valores(valor)
  valor.is_a?(Hash) ? Conjunto.new(valor) : valor
end