Class: Nfe::Services::Regress::ProtNFe

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/nfe/services/regress/protNFe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chNFeObject

Returns the value of attribute chNFe.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def chNFe
  @chNFe
end

#cStatObject

Returns the value of attribute cStat.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def cStat
  @cStat
end

#dhRecbtoObject

Returns the value of attribute dhRecbto.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def dhRecbto
  @dhRecbto
end

#digValObject

Returns the value of attribute digVal.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def digVal
  @digVal
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def id
  @id
end

#nProtObject

Returns the value of attribute nProt.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def nProt
  @nProt
end

#tpAmbObject

Returns the value of attribute tpAmb.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def tpAmb
  @tpAmb
end

#verAplicObject

Returns the value of attribute verAplic.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def verAplic
  @verAplic
end

#versaoObject

Returns the value of attribute versao.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def versao
  @versao
end

#xMotivoObject

Returns the value of attribute xMotivo.



7
8
9
# File 'lib/nfe/services/regress/protNFe.rb', line 7

def xMotivo
  @xMotivo
end

Instance Method Details

#parse!(xml) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nfe/services/regress/protNFe.rb', line 10

def parse!(xml)
  doc = Nokogiri::XML(xml)

  @versao = doc.root.attribute("versao").text

  if doc.css("infProt").attribute("Id").present?
    @id = doc.css("infProt").attribute("Id").text
  end

  @tpAmb = doc.css("infProt > tpAmb").text
  @verAplic = doc.css("infProt > verAplic").text
  @chNFe = doc.css("infProt > chNFe").text
  @dhRecbto = DateTime.strptime(doc.css("infProt > dhRecbto").text, "%Y-%m-%dT%H:%M:%S%:z")
  @nProt = doc.css("infProt > nProt").text
  @digVal = doc.css("infProt > digVal").text
  @cStat = doc.css("infProt > cStat").text.to_i
  @xMotivo = doc.css("infProt > xMotivo").text
end

#to_xmlObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nfe/services/regress/protNFe.rb', line 29

def to_xml
  xml = Builder::XmlMarkup.new


  xml.protNFe(versao: versao) do |root|
    attributes = {}
    attributes[:Id] = @id if @id.present?

    root.infProt(attributes) do |node|
      node.tpAmb @tpAmb
      node.verAplic @verAplic
      node.chNFe @chNFe
      node.dhRecbto  @dhRecbto.strftime("%Y-%m-%dT%H:%M:%S%:z")
      node.nProt @nProt
      node.digVal @digVal
      node.cStat @cStat
      node.xMotivo @xMotivo
    end
  end

  xml.target!
end