Class: Nfe::Reader::Base
- Inherits:
-
Object
- Object
- Nfe::Reader::Base
- Defined in:
- lib/nfe_reader.rb
Instance Attribute Summary collapse
-
#authorizations ⇒ Object
readonly
Returns the value of attribute authorizations.
-
#cane ⇒ Object
readonly
Returns the value of attribute cane.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#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.
-
#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.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(file) ⇒ Base
Returns a new instance of Base.
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 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/nfe_reader.rb', line 19 def initialize(file) xml = Nokogiri::XML(file).to_hash # Versao da NFe @version = 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] # Numero da Nfe @number = xml[:Id] # Identificação da Nota Fiscal eletrônica @header = Nfe::Header.new(xml[:ide]) # Identificação do Emitente da Nota Fiscal eletrônica @provider = Nfe::Provider.new(xml[:emit]) # Identificação do Fisco Emitente da NF-e if xml[:avulsa] @fiscal = Nfe::Fiscal.new(xml[:avulsa]) end # Identificação do Destinatário da Nota Fiscal eletrônica @customer = Nfe::Customer.new(xml[:dest]) # Informacoes Adicional if xml[:infAdic] @information = Nfe::Information.new(xml[:infAdic]) end # Detalhamento de Produtos e Serviços da NF-e @products = [] if xml[:det].is_a? Array xml[:det].each do |product| @products << Nfe::Product.new(product) end else @products << Nfe::Product.new(xml[:det]) end # Totalizadores @total = Nfe::Total.new(xml[:total]) # Informacao de Pagamento if xml[:cobr] @collection = Nfe::Collection.new(xml[:cobr]) end # Transporte if xml[:transp] @transport = Nfe::Transport.new(xml[:transp]) end # Identificação do Local de Entrega if xml[:retirada] @removal = Nfe::Removal.new(xml[:retirada]) end # Identificação do Local de Retirada if xml[:entrega] @delivery = Nfe::Delivery.new(xml[:entrega]) end # Autorização para obter XML @authorizations = [] if xml[:autXML].is_a? Array xml[:autXML].each do |product| @authorizations << Nfe::Authorization.new(product) end elsif xml[:autXML].is_a? Hash @authorizations << Nfe::Authorization.new(xml[:autXML]) end # Informacoes de Comercio Exterior if xml[:exporta] @export = Nfe::Export.new(xml[:exporta]) end # Informacoes de Compra if xml[:compra] @purchase = Nfe::Purchase.new(xml[:compra]) end # Cana de Acucar if xml[:cana] @cane = Nfe::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.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def @authorizations end |
#cane ⇒ Object (readonly)
Returns the value of attribute cane.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def cane @cane end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def client @client end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def collection @collection end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def customer @customer end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def date @date end |
#delivery ⇒ Object (readonly)
Returns the value of attribute delivery.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def delivery @delivery end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def description @description end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def digest @digest end |
#enviroment ⇒ Object (readonly)
Returns the value of attribute enviroment.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def enviroment @enviroment end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def error @error end |
#export ⇒ Object (readonly)
Returns the value of attribute export.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def export @export end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def header @header end |
#information ⇒ Object (readonly)
Returns the value of attribute information.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def information @information end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def key @key end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def number @number end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def products @products end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def protocol @protocol end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def provider @provider end |
#purchase ⇒ Object (readonly)
Returns the value of attribute purchase.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def purchase @purchase end |
#removal ⇒ Object (readonly)
Returns the value of attribute removal.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def removal @removal end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def signature @signature end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def status @status end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def total @total end |
#trace ⇒ Object (readonly)
Returns the value of attribute trace.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def trace @trace end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def transport @transport end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def version @version end |
#version_app ⇒ Object (readonly)
Returns the value of attribute version_app.
13 14 15 |
# File 'lib/nfe_reader.rb', line 13 def version_app @version_app end |
Instance Method Details
#error? ⇒ Boolean
130 131 132 |
# File 'lib/nfe_reader.rb', line 130 def error? !error.nil? end |