Class: Nfe::Models::NFe
- Inherits:
-
Object
- Object
- Nfe::Models::NFe
- Includes:
- ActiveModel::Model, Helpers::XmlModel::NfeModel
- Defined in:
- lib/nfe/models/NFe.rb
Instance Attribute Summary collapse
-
#infNFe ⇒ Object
Returns the value of attribute infNFe.
-
#signature ⇒ Object
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ NFe
constructor
A new instance of NFe.
- #parse!(xml) ⇒ Object
- #to_xml ⇒ Object
Methods included from Helpers::XmlModel::NfeModel
#add_elements, #check_present, included, #parse_elements, #present?, #validate_optional_attributes, #validate_required_attributes
Constructor Details
Instance Attribute Details
#infNFe ⇒ Object
Returns the value of attribute infNFe.
7 8 9 |
# File 'lib/nfe/models/NFe.rb', line 7 def infNFe @infNFe end |
#signature ⇒ Object
Returns the value of attribute signature.
7 8 9 |
# File 'lib/nfe/models/NFe.rb', line 7 def signature @signature end |
Class Method Details
.namespace ⇒ Object
16 17 18 |
# File 'lib/nfe/models/NFe.rb', line 16 def self.namespace "http://www.portalfiscal.inf.br/nfe" end |
Instance Method Details
#parse!(xml) ⇒ Object
20 21 22 23 24 25 26 27 |
# 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 ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |