Class: Produto

Inherits:
Object
  • Object
show all
Defined in:
lib/nfe/entidades/infNFe/det/produto.rb

Overview

module NFe

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Produto



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 23

def initialize(attrs = {})
  self.cProd  = attrs[:cProd]
  self.cEAN   = attrs[:cEAN]
  self.xProd  = attrs[:xProd]
  self.NCM    = attrs[:NCM]
  self.EXTIPI = attrs[:EXTIPI]
  self.CFOP   = attrs[:CFOP]
  self.uCom   = attrs[:uCom]
  self.qCom   = attrs[:qCom]
  self.vUnCom = attrs[:vUnCom]
  self.vProd  = attrs[:vProd]
  self.cEANTrib = attrs[:cEANTrib]
  self.uTrib  = attrs[:uTrib]
  self.qTrib  = attrs[:qTrib]
  self.vUnTrib = attrs[:vUnTrib]
  self.indTot  = attrs[:indTot]
  self.xPed    = attrs[:xPed]
  self.all_products = []
end

Instance Attribute Details

#all_productsObject

Returns the value of attribute all_products.



21
22
23
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 21

def all_products
  @all_products
end

#cEANObject

Returns the value of attribute cEAN.



5
6
7
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 5

def cEAN
  @cEAN
end

#cEANTribObject

Returns the value of attribute cEANTrib.



14
15
16
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 14

def cEANTrib
  @cEANTrib
end

#CFOPObject

Returns the value of attribute CFOP.



9
10
11
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 9

def CFOP
  @CFOP
end

#cProdObject

Returns the value of attribute cProd.



4
5
6
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 4

def cProd
  @cProd
end

#EXTIPIObject

Returns the value of attribute EXTIPI.



8
9
10
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 8

def EXTIPI
  @EXTIPI
end

#indTotObject

Returns the value of attribute indTot.



18
19
20
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 18

def indTot
  @indTot
end

#NCMObject

Returns the value of attribute NCM.



7
8
9
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 7

def NCM
  @NCM
end

#qComObject

Returns the value of attribute qCom.



11
12
13
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 11

def qCom
  @qCom
end

#qTribObject

Returns the value of attribute qTrib.



16
17
18
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 16

def qTrib
  @qTrib
end

#uComObject

Returns the value of attribute uCom.



10
11
12
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 10

def uCom
  @uCom
end

#uTribObject

Returns the value of attribute uTrib.



15
16
17
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 15

def uTrib
  @uTrib
end

#vProdObject

Returns the value of attribute vProd.



13
14
15
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 13

def vProd
  @vProd
end

#vUnComObject

Returns the value of attribute vUnCom.



12
13
14
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 12

def vUnCom
  @vUnCom
end

#vUnTribObject

Returns the value of attribute vUnTrib.



17
18
19
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 17

def vUnTrib
  @vUnTrib
end

#xPedObject

Returns the value of attribute xPed.



19
20
21
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 19

def xPed
  @xPed
end

#xProdObject

Returns the value of attribute xProd.



6
7
8
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 6

def xProd
  @xProd
end

Instance Method Details

#attributesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 43

def attributes
  { "cProd" => cProd,
    "cEAN" => cEAN,
    "xProd" => xProd,
    "NCM" => NCM,
    "EXTIPI" => EXTIPI,
    "CFOP" => CFOP,
    "uCom" => uCom,
    "qCom" => qCom,
    "vUnCom" => vUnCom,
    "vProd" => vProd,
    "cEANTrib" => cEANTrib,
    "uTrib" => uTrib,
    "qTrib" => qTrib,
    "vUnTrib" => vUnTrib,
    "indTot" => indTot,
    "xPed" => xPed
  }
end

#attributes=(params) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 63

def attributes=(params)
  self.cProd  = params["cProd"]
  self.cEAN   = params["cEAN"]
  self.xProd  = params["xProd"]
  self.NCM    = params["NCM"]
  self.EXTIPI = params["EXTIPI"]
  self.CFOP   = params["CFOP"]
  self.uCom   = params["uCom"]
  self.qCom   = params["qCom"]
  self.vUnCom = params["vUnCom"]
  self.vProd  = params["vProd"]
  self.cEANTrib = params["cEANTrib"]
  self.uTrib  = params["uTrib"]
  self.qTrib  = params["qTrib"]
  self.vUnTrib = params["vUnTrib"]
  self.indTot = params["indTot"]
  self.xPed   = params["xPed"]
end

#xml_to_hash(xml) ⇒ Object

file xml



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/nfe/entidades/infNFe/det/produto.rb', line 82

def xml_to_hash(xml) #file xml
  doc = Nokogiri::XML(File.open(xml))
  prods = doc.elements.css('prod').map do |p| 
    {
      'cProd' => p.css('cProd').text,
      'cEAN' => p.css('cEAN').text,
      'xProd' => p.css('xProd').text,
      'NCM' => p.css('NCM').text,
      'EXTIPI' => p.css('EXTIPI').text,
      'CFOP' => p.css('CFOP').text,
      'uCom' => p.css('uCom').text,
      'qCom' => p.css('qCom').text,
      'vUnCom' => p.css('vUnCom').text,
      'vProd' => p.css('vProd').text,
      'cEANTrib' => p.css('cEANTrib').text,
      'uTrib' => p.css('uTrib').text,
      'qTrib' => p.css('qTrib').text,
      'vUnTrib' => p.css('vUnTrib').text,
      'indTot' => p.css('indTot').text,
      'xPed' => p.css('xPed').text
    }
  end
  prods.each {|p| self.all_products.push(p) }
end