Class: NfeReader::Nfe
- Inherits:
-
Object
- Object
- NfeReader::Nfe
- Includes:
- AttributeHelper, CreatorHelper
- Defined in:
- lib/nfe_reader/nfe.rb
Constant Summary
Constants included from AttributeHelper
Instance Attribute Summary collapse
-
#authorizations ⇒ Object
readonly
Returns the value of attribute authorizations.
-
#billing ⇒ Object
readonly
Returns the value of attribute billing.
-
#cane ⇒ Object
readonly
Returns the value of attribute cane.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#delivery ⇒ Object
readonly
Returns the value of attribute delivery.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#enviroment ⇒ Object
readonly
Returns the value of attribute enviroment.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#fiscal ⇒ Object
readonly
Returns the value of attribute fiscal.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#information ⇒ Object
readonly
Returns the value of attribute information.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#products ⇒ Object
readonly
Returns the value of attribute products.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#purchase ⇒ Object
readonly
Returns the value of attribute purchase.
-
#removal ⇒ Object
readonly
Returns the value of attribute removal.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#trace ⇒ Object
readonly
Returns the value of attribute trace.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#version_app ⇒ Object
readonly
Returns the value of attribute version_app.
-
#version_schema ⇒ Object
readonly
Returns the value of attribute version_schema.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(file) ⇒ Nfe
constructor
A new instance of Nfe.
Methods included from CreatorHelper
#create_resource, #create_resources, #to_array
Methods included from AttributeHelper
#attributes, #attributes_to_hash
Constructor Details
#initialize(file) ⇒ Nfe
Returns a new instance of Nfe.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/nfe_reader/nfe.rb', line 12 def initialize(file) xml = file.is_a?(Nokogiri::XML::Document) ? file : Nokogiri::XML(file) xml = xml.to_hash if xml[:nfeProc] # Versao da NFe @version_schema = xml[:nfeProc][:versao] # Assinatura @signature = xml[:nfeProc][:NFe][:Signature] # Protocolo if xml[:nfeProc][:protNFe] protocol = xml[:nfeProc][:protNFe][:infProt] @enviroment = protocol[:tpAmb] @version_app = protocol[:verAplic] @key = protocol[:chNFe] @date = protocol[:dhRecbto] @protocol = protocol[:nProt] @digest = protocol[:digVal] @status = protocol[:cStat] @description = protocol[:xMotivo] end xml = xml[:nfeProc][:NFe][:infNFe] else xml = xml[:NFe][:infNFe] end # Numero da Nfe @number = xml[:Id] # Versao da NFe @version = xml[:versao] # Identificação da Nota Fiscal eletrônica @header = Header.new(xml[:ide]) # Identificação do Emitente da Nota Fiscal eletrônica @provider = Provider.new(xml[:emit]) # Identificação do Fisco Emitente da NF-e if xml[:avulsa] @fiscal = Fiscal.new(xml[:avulsa]) end # Identificação do Destinatário da Nota Fiscal eletrônica @customer = Customer.new(xml[:dest]) # Informacoes Adicional if xml[:infAdic] @information = Information.new(xml[:infAdic]) end # Detalhamento de Produtos e Serviços da NF-e @products = create_resources(Product, xml[:det]) # Totalizadores @total = Total.new(xml[:total]) # Informacao de Pagamento if xml[:cobr] @billing = Billing.new(xml[:cobr]) end # Transporte if xml[:transp] @transport = Transport.new(xml[:transp]) end # Identificação do Local de Entrega if xml[:retirada] @removal = Removal.new(xml[:retirada]) end # Identificação do Local de Retirada if xml[:entrega] @delivery = Delivery.new(xml[:entrega]) end # Autorização para obter XML @authorizations = create_resources(Authorization, xml[:autXML]) # Informacoes de Comercio Exterior if xml[:exporta] @export = Export.new(xml[:exporta]) end # Informacoes de Compra if xml[:compra] @purchase = Purchase.new(xml[:compra]) end # Cana de Acucar if xml[:cana] @cane = Cane.new(xml[:cana]) end rescue => exception @error = exception @trace = exception.backtrace ensure file.close if file.respond_to? :close end |
Instance Attribute Details
#authorizations ⇒ Object (readonly)
Returns the value of attribute authorizations.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def @authorizations end |
#billing ⇒ Object (readonly)
Returns the value of attribute billing.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def billing @billing end |
#cane ⇒ Object (readonly)
Returns the value of attribute cane.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def cane @cane end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def client @client end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def customer @customer end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def date @date end |
#delivery ⇒ Object (readonly)
Returns the value of attribute delivery.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def delivery @delivery end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def description @description end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def digest @digest end |
#enviroment ⇒ Object (readonly)
Returns the value of attribute enviroment.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def enviroment @enviroment end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def error @error end |
#export ⇒ Object (readonly)
Returns the value of attribute export.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def export @export end |
#fiscal ⇒ Object (readonly)
Returns the value of attribute fiscal.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def fiscal @fiscal end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def header @header end |
#information ⇒ Object (readonly)
Returns the value of attribute information.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def information @information end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def key @key end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def number @number end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def products @products end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def protocol @protocol end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def provider @provider end |
#purchase ⇒ Object (readonly)
Returns the value of attribute purchase.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def purchase @purchase end |
#removal ⇒ Object (readonly)
Returns the value of attribute removal.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def removal @removal end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def signature @signature end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def status @status end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def total @total end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def trace @trace end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def transport @transport end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def version @version end |
#version_app ⇒ Object (readonly)
Returns the value of attribute version_app.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def version_app @version_app end |
#version_schema ⇒ Object (readonly)
Returns the value of attribute version_schema.
6 7 8 |
# File 'lib/nfe_reader/nfe.rb', line 6 def version_schema @version_schema end |
Instance Method Details
#error? ⇒ Boolean
117 118 119 |
# File 'lib/nfe_reader/nfe.rb', line 117 def error? !error.nil? end |