Class: Nfe::Reader::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/nfe_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ 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
# File 'lib/nfe_reader.rb', line 19

def initialize(file)
  xml = Nokogiri::XML(file)

  xml = xml.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
ensure
  file.close
end

Instance Attribute Details

#authorizationsObject (readonly)

Returns the value of attribute authorizations.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def authorizations
  @authorizations
end

#caneObject (readonly)

Returns the value of attribute cane.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def cane
  @cane
end

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def client
  @client
end

#collectionObject (readonly)

Returns the value of attribute collection.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def collection
  @collection
end

#customerObject (readonly)

Returns the value of attribute customer.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def customer
  @customer
end

#dateObject (readonly)

Returns the value of attribute date.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def date
  @date
end

#deliveryObject (readonly)

Returns the value of attribute delivery.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def delivery
  @delivery
end

#descriptionObject (readonly)

Returns the value of attribute description.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def description
  @description
end

#digestObject (readonly)

Returns the value of attribute digest.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def digest
  @digest
end

#enviromentObject (readonly)

Returns the value of attribute enviroment.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def enviroment
  @enviroment
end

#exportObject (readonly)

Returns the value of attribute export.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def export
  @export
end

#headerObject (readonly)

Returns the value of attribute header.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def header
  @header
end

#informationObject (readonly)

Returns the value of attribute information.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def information
  @information
end

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def key
  @key
end

#numberObject (readonly)

Returns the value of attribute number.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def number
  @number
end

#productsObject (readonly)

Returns the value of attribute products.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def products
  @products
end

#protocolObject (readonly)

Returns the value of attribute protocol.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def protocol
  @protocol
end

#providerObject (readonly)

Returns the value of attribute provider.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def provider
  @provider
end

#purchaseObject (readonly)

Returns the value of attribute purchase.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def purchase
  @purchase
end

#removalObject (readonly)

Returns the value of attribute removal.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def removal
  @removal
end

#signatureObject (readonly)

Returns the value of attribute signature.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def signature
  @signature
end

#statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def status
  @status
end

#totalObject (readonly)

Returns the value of attribute total.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def total
  @total
end

#transportObject (readonly)

Returns the value of attribute transport.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def transport
  @transport
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def version
  @version
end

#version_appObject (readonly)

Returns the value of attribute version_app.



13
14
15
# File 'lib/nfe_reader.rb', line 13

def version_app
  @version_app
end