Class: DfeTaxweb::Atributos
- Inherits:
-
Object
- Object
- DfeTaxweb::Atributos
- Includes:
- Singleton
- Defined in:
- lib/dfe_taxweb/atributos.rb
Instance Attribute Summary collapse
-
#atributos_hash ⇒ Object
readonly
Returns the value of attribute atributos_hash.
-
#atributos_list ⇒ Object
readonly
Returns the value of attribute atributos_list.
-
#atributos_object ⇒ Object
readonly
Returns the value of attribute atributos_object.
Instance Method Summary collapse
- #atributo(path, conjunto = nil) ⇒ Object
- #colecao ⇒ Object
-
#initialize ⇒ Atributos
constructor
A new instance of Atributos.
- #lista ⇒ Object
Constructor Details
#initialize ⇒ Atributos
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_hash ⇒ Object (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_list ⇒ Object (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_object ⇒ Object (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 |
#colecao ⇒ Object
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 |
#lista ⇒ Object
15 16 17 |
# File 'lib/dfe_taxweb/atributos.rb', line 15 def lista @atributos_list ||= tree_to_list(@atributos_hash) end |