class Nfe::Models::NFe

Attributes

infNFe[RW]
signature[RW]

Public Class Methods

namespace() click to toggle source
# File lib/nfe/models/NFe.rb, line 16
def self.namespace
  "http://www.portalfiscal.inf.br/nfe"
end
new() click to toggle source
# File lib/nfe/models/NFe.rb, line 11
def initialize
  @infNFe = Nfe::Models::InfNFe.new
  @signature = Nfe::Models::Signature.new
end

Public Instance Methods

parse!(xml) click to toggle source
# File lib/nfe/models/NFe.rb, line 20
def parse!(xml)
  doc = Nokogiri::XML(xml)

  @infNFe.parse!(doc.css("infNFe").to_xml)

  sign = doc.xpath("//ds:Signature", ds: Signature.namespace).to_xml
  @signature.parse!(sign)
end
to_xml() click to toggle source
# File lib/nfe/models/NFe.rb, line 29
def to_xml
  xml = Builder::XmlMarkup.new

  xml.NFe(xmlns: Nfe::Models::NFe.namespace) do |nfe|

    nfe.infNFe({versao: infNFe.versao, Id: infNFe.id}) do |node|
      node << @infNFe.to_xml
    end

    nfe.Signature(xmlns: Signature.namespace) do |node|
      node << @signature.value
    end
  end

  xml.target!
end