Class: RubyXmlNfe::Items

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_xml_nfe/items.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, items) ⇒ Items

Returns a new instance of Items.



8
9
10
11
# File 'lib/ruby_xml_nfe/items.rb', line 8

def initialize(xml, items)
  @xml = xml
  @items = items
end

Instance Attribute Details

#infAdProdObject (readonly)

Returns the value of attribute infAdProd.



6
7
8
# File 'lib/ruby_xml_nfe/items.rb', line 6

def infAdProd
  @infAdProd
end

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/ruby_xml_nfe/items.rb', line 6

def items
  @items
end

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/ruby_xml_nfe/items.rb', line 6

def xml
  @xml
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_xml_nfe/items.rb', line 13

def build
  items.map.with_index do |item, index|
    xml.det(nItem: index + 1) do
      prod = RubyXmlNfe::Prod.new(xml, item[:prod])
      prod.build

      imposto = RubyXmlNfe::Imposto.new(xml, item[:imposto])
      imposto.build

      xml.infAdProd item[:infAdProd] if item[:infAdProd]
    end
  end
end