Class: DfeTaxweb::Atributos

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/dfe_taxweb/atributos.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAtributos

Returns a new instance of Atributos.



10
11
12
13
# File 'lib/dfe_taxweb/atributos.rb', line 10

def initialize
  atributos_h = YAML.load(File.read(File.join(__dir__, 'atributos.yml')))
  @atributos_hash ||= atributos_h['documento'].deep_symbolize_keys || {}
end

Instance Attribute Details

#atributos_hashObject (readonly)

Returns the value of attribute atributos_hash.



8
9
10
# File 'lib/dfe_taxweb/atributos.rb', line 8

def atributos_hash
  @atributos_hash
end

#atributos_listObject (readonly)

Returns the value of attribute atributos_list.



8
9
10
# File 'lib/dfe_taxweb/atributos.rb', line 8

def atributos_list
  @atributos_list
end

#atributos_objectObject (readonly)

Returns the value of attribute atributos_object.



8
9
10
# File 'lib/dfe_taxweb/atributos.rb', line 8

def atributos_object
  @atributos_object
end

Instance Method Details

#atributo(path, conjunto = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dfe_taxweb/atributos.rb', line 25

def atributo(path, conjunto=nil)
  conjunto = @atributos_hash if conjunto.nil?
  attrs = 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
  DfeTaxweb::Atributo.new(attrs, path)
end

#colecaoObject



19
20
21
22
23
# File 'lib/dfe_taxweb/atributos.rb', line 19

def colecao
  @atributos_object ||= lista.map do |atributo_path|
    atributo(atributo_path)
  end.compact
end

#listaObject



15
16
17
# File 'lib/dfe_taxweb/atributos.rb', line 15

def lista
  @atributos_list ||= tree_to_list(@atributos_hash)
end