spf_barcode 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c42354e677464232961bb3b825938a674e1e2277
4
- data.tar.gz: 2ff0e2b58d14e73541cbdd370841d32b92014c14
3
+ metadata.gz: fa2308a1f7f8ca96726873fa6620cff21f9df66b
4
+ data.tar.gz: 900fdd0efef6669265bc2c002590cd42b67199c4
5
5
  SHA512:
6
- metadata.gz: a09cb49fe18390ee8b98b3bd57a5d977733da045ddc73121867ee7ddc194657a63b84bdf1b9da790c740d6f2fef2f7b2d05e314404bf5d816e5772f31ee5d9eb
7
- data.tar.gz: bbea65cc6dc0f17df7603fc8dfa36bc791025a3c0b8c10fcb49abfc9d8fedf9e0190ce74e3d5850b1553b3e48cf00a6466aedaf7d5586cc23e6eb2658e5e1981
6
+ metadata.gz: 197fc0f31224cbb7e893a78aa93af6584b536f8a2d8eab3358d9e2e12be736237c8a4ba4425b0b4462b56b73d95e381eb255c02b75d519085fc4e2afe44039ca
7
+ data.tar.gz: 7d705c7227e4cbd7213eb8870e83e36cb03edade21a195ab46125f2556245f67e1c7f9ba49083c926fc3d0ee41143c35f2580776c3390728f1db7b211e1cd4b6
@@ -1,3 +1,3 @@
1
1
  module SpfBarcode
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/spf_barcode.rb CHANGED
@@ -1,5 +1,109 @@
1
- module SpfBarcode
2
- def probando
3
- "PRUEBA OK 2"
1
+ # encoding: utf-8
2
+ class BarcodeOptimaDecode
3
+ def initialize(barcode)
4
+ @barcode = barcode
5
+ valida_length_barcode
6
+ end
7
+
8
+ # desactivo la validacion para que también pueda leer codigos viejos:
9
+ # 8800111100101
10
+ # 001111-001-001
11
+ def valida_length_barcode
12
+ # raise "Error: la cantidad de dígitos del barcode es incorrecta. Debe ser 15. Es #{@barcode.length}" unless @barcode.length == 15
13
+ end
14
+
15
+ def decode_pedido
16
+ @pedido = Pedido.find_by_id(@barcode[2..7]) || (raise "Error al obtener el pedido decodificando el código de barra")
17
+ end
18
+
19
+ def decode_item
20
+ cardinalidad_item = @barcode[8..9].to_i
21
+ @item = decode_cardinalidad_item(cardinalidad_item) || (raise "Error al obtener el item decodificando el código de barra")
22
+ end
23
+
24
+ def decode_item_medida
25
+ cardinalidad_item_medida = @barcode[10..12].to_i
26
+ @item_medida = decode_cardinalidad_item_medida(cardinalidad_item_medida) || (raise "Error al obtener la medida decodificando el código de barra")
27
+ end
28
+
29
+ def decode_objeto
30
+ barcode_header = @barcode[0..1].to_i
31
+ barcode_objeto = @barcode[13..14].to_i
32
+
33
+ case barcode_header
34
+ when 80 then
35
+ @elemento = decode_cardinalidad_elemento(barcode_objeto) || (raise "Error al obtener el elemento decodificando el código de barra")
36
+ when 81 then
37
+ @componente = decode_orden_componente(barcode_objeto) || (raise "Error al obtener el componente decodificando el código de barra")
38
+ when 82 then
39
+ @composicion = decode_composicion || (raise "Error al obtener la composición decodificando el código de barra")
40
+ else
41
+ end
42
+
43
+
44
+ end
45
+
46
+ def decode
47
+ decode_pedido
48
+ decode_item
49
+ decode_item_medida
50
+ decode_objeto
51
+ self
52
+ end
53
+
54
+ def pedido
55
+ @pedido
56
+ end
57
+
58
+ def item
59
+ @item
60
+ end
61
+
62
+ def item_medida
63
+ @item_medida
64
+ end
65
+
66
+ def elemento
67
+ @elemento
68
+ end
69
+
70
+ def componente
71
+ @componente || @elemento.try(:componente)
72
+ end
73
+
74
+ def composicion
75
+ @composicion || @elemento.try(:componente).try(:composicion) || @componente.try(:composicion)
76
+ end
77
+
78
+
79
+
80
+ def decode_cardinalidad_item(cardinalidad)
81
+ @pedido.items.order(:id).each do |item|
82
+ return item if item.cardinalidad == cardinalidad
83
+ end
84
+ false
85
+ end
86
+
87
+ def decode_cardinalidad_item_medida(cardinalidad)
88
+ @item.item_medidas.order(:id).each do |item_medida|
89
+ return item_medida if item_medida.cardinalidad == cardinalidad
90
+ end
91
+ false
92
+ end
93
+
94
+ def decode_cardinalidad_elemento(cardinalidad)
95
+ elementos_materiales = @item.composicion.get_elementos_materiales_ordenados
96
+ elementos_materiales.each do |elemento|
97
+ return elemento if elemento.cardinalidad == cardinalidad
98
+ end
99
+ false
100
+ end
101
+
102
+ def decode_orden_componente(orden)
103
+ @item.composicion.componentes.select{|c| c.orden == orden}.compact[0]
104
+ end
105
+
106
+ def decode_composicion
107
+ @item.composicion
4
108
  end
5
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spf_barcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Ramseyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-26 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails