Class: RubyXmlNfe::Xml

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params) ⇒ Xml

Returns a new instance of Xml.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_xml_nfe/xml.rb', line 19

def initialize(name, params)
  @name = name
  @chNFe = params[:chNFe]
  @ide_params = params[:ide]
  @emit_params = params[:emit]
  @dest_params = params[:dest]
  @aut_xml_params = params[:autXML]
  @items_params = params[:items]
  @total_params = params[:total]
  @transp_params = params[:transp]
  @cobr_params = params[:cobr]
  @pag_params = params[:pag]
  @inf_adc_params = params[:infAdic]
end

Instance Attribute Details

#aut_xml_paramsObject (readonly)

Returns the value of attribute aut_xml_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def aut_xml_params
  @aut_xml_params
end

#chNFeObject (readonly)

Returns the value of attribute chNFe.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def chNFe
  @chNFe
end

#cobr_paramsObject (readonly)

Returns the value of attribute cobr_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def cobr_params
  @cobr_params
end

#dest_paramsObject (readonly)

Returns the value of attribute dest_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def dest_params
  @dest_params
end

#emit_paramsObject (readonly)

Returns the value of attribute emit_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def emit_params
  @emit_params
end

#ide_paramsObject (readonly)

Returns the value of attribute ide_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def ide_params
  @ide_params
end

#inf_adc_paramsObject (readonly)

Returns the value of attribute inf_adc_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def inf_adc_params
  @inf_adc_params
end

#items_paramsObject (readonly)

Returns the value of attribute items_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def items_params
  @items_params
end

#pag_paramsObject (readonly)

Returns the value of attribute pag_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def pag_params
  @pag_params
end

#total_paramsObject (readonly)

Returns the value of attribute total_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def total_params
  @total_params
end

#transp_paramsObject (readonly)

Returns the value of attribute transp_params.



15
16
17
# File 'lib/ruby_xml_nfe/xml.rb', line 15

def transp_params
  @transp_params
end

Instance Method Details

#buildObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ruby_xml_nfe/xml.rb', line 34

def build
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.NFe(xmlns: "http://www.portalfiscal.inf.br/nfe") do
      xml.infNFe(Id: "NFe#{chNFe}", versao: "4.00") do
        ide = RubyXmlNfe::Ide.new(xml, ide_params)
        ide.build

        emit = RubyXmlNfe::Emit.new(xml, emit_params)
        emit.build

        dest = RubyXmlNfe::Dest.new(xml, dest_params)
        dest.build

        if aut_xml_params
          aut_xml = RubyXmlNfe::AutXml.new(xml, aut_xml_params)
          aut_xml.build
        end

        items = RubyXmlNfe::Items.new(xml, items_params)
        items.build

        total = RubyXmlNfe::Total.new(xml, total_params)
        total.build

        transp = RubyXmlNfe::Transp.new(xml, transp_params)
        transp.build

        if cobr_params
          cobr = RubyXmlNfe::Cobr.new(xml, cobr_params)
          cobr.build
        end

        pag = RubyXmlNfe::Pag.new(xml, pag_params)
        pag.build

        inf_adic = RubyXmlNfe::InfAdic.new(xml, inf_adc_params)
        inf_adic.build
      end
    end
  end

  builder.to_xml
end