barcode1dtools 0.9.9.0 → 0.9.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/barcode1dtools/codabar.rb +1 -1
- data/lib/barcode1dtools/code128.rb +25 -7
- data/test/test_barcode1dcode128.rb +14 -4
- metadata +27 -51
@@ -22,7 +22,7 @@ module Barcode1DTools
|
|
22
22
|
#
|
23
23
|
# Additionally, the caller must present the start and stop
|
24
24
|
# characters as part of the value. When decoding, the start/stop
|
25
|
-
#
|
25
|
+
# characters will be presented as A, B, C, or D.
|
26
26
|
#
|
27
27
|
# val = "A29322930C"
|
28
28
|
# bc = Barcode1DTools::Codabar.new(val)
|
@@ -115,7 +115,7 @@ module Barcode1DTools
|
|
115
115
|
# underscore, then has nul to \x1f. Finally, it has FNC 1-4.
|
116
116
|
CODE_A_TO_ASCII = ((32..95).to_a + (0..31).to_a).collect { |c| [c].pack('C') } + [ :fnc_3, :fnc_2, :shift_b, :code_c, :code_b, :fnc_4, :fnc_1, :start_a, :start_b, :start_c, :stop ]
|
117
117
|
ASCII_TO_CODE_A = (0..(CODE_A_TO_ASCII.length-1)).inject({}) { |a,c| a[CODE_A_TO_ASCII[c]] = c; a }
|
118
|
-
CODE_A_TO_HIGH_ASCII = CODE_A_TO_ASCII.collect { |a| a.is_a?(Symbol) ? a : [a.unpack("C").first+128].pack("C") }
|
118
|
+
CODE_A_TO_HIGH_ASCII = CODE_A_TO_ASCII.collect { |a| a.is_a?(Symbol) ? a : [a.unpack("C").first+128].pack("C") }.collect { |c| RUBY_VERSION < "1.9" || c.is_a?(Symbol) ? c : c.force_encoding('ISO-8859-1') }
|
119
119
|
HIGH_ASCII_TO_CODE_A = (0..(CODE_A_TO_HIGH_ASCII.length-1)).inject({}) { |a,c| a[CODE_A_TO_HIGH_ASCII[c]] = c; a }
|
120
120
|
|
121
121
|
# Code B encodes ASCII space (\x20, dec. 32) to DEL (\x7f,
|
@@ -124,7 +124,7 @@ module Barcode1DTools
|
|
124
124
|
# different position than in set A.
|
125
125
|
CODE_B_TO_ASCII = (32..127).collect { |c| [c].pack('C') } + [ :fnc_3, :fnc_2, :shift_a, :code_c, :fnc_4, :code_a, :fnc_1, :start_a, :start_b, :start_c, :stop ]
|
126
126
|
ASCII_TO_CODE_B = (0..(CODE_B_TO_ASCII.length-1)).inject({}) { |a,c| a[CODE_B_TO_ASCII[c]] = c; a }
|
127
|
-
CODE_B_TO_HIGH_ASCII = CODE_B_TO_ASCII.collect { |a| a.is_a?(Symbol) ? a : [a.unpack("C").first+128].pack("C") }
|
127
|
+
CODE_B_TO_HIGH_ASCII = CODE_B_TO_ASCII.collect { |a| a.is_a?(Symbol) ? a : [a.unpack("C").first+128].pack("C") }.collect { |c| RUBY_VERSION < "1.9" || c.is_a?(Symbol) ? c : c.force_encoding('ISO-8859-1') }
|
128
128
|
HIGH_ASCII_TO_CODE_B = (0..(CODE_B_TO_HIGH_ASCII.length-1)).inject({}) { |a,c| a[CODE_B_TO_HIGH_ASCII[c]] = c; a }
|
129
129
|
|
130
130
|
# Code C encodes digit pairs 00 to 99 as well as FNC 1.
|
@@ -255,7 +255,7 @@ module Barcode1DTools
|
|
255
255
|
end
|
256
256
|
# Make sure it's Latin-1 for Ruby 1.9+
|
257
257
|
if RUBY_VERSION >= "1.9"
|
258
|
-
ret = ret.collect { |c| c.force_encoding('ISO-8859-1') }
|
258
|
+
ret = ret.collect { |c| c.is_a?(Symbol) ? c : c.force_encoding('ISO-8859-1') }
|
259
259
|
end
|
260
260
|
if options[:raw_array]
|
261
261
|
ret.push(md[2].unpack('C').first)
|
@@ -325,6 +325,9 @@ module Barcode1DTools
|
|
325
325
|
while x < map_a.length - 1 do
|
326
326
|
map_a_len = map_a.index('-',x).to_i - x
|
327
327
|
map_b_len = map_b.index('-',x).to_i - x
|
328
|
+
if map_a_len==0 && map_b_len==0
|
329
|
+
raise "Ack! Bad mapping: #{map_a} & #{map_b}"
|
330
|
+
end
|
328
331
|
if map_a_len >= map_b_len
|
329
332
|
codepoints += map_a[x,map_a_len]
|
330
333
|
x += map_a_len
|
@@ -439,7 +442,7 @@ module Barcode1DTools
|
|
439
442
|
|
440
443
|
end
|
441
444
|
|
442
|
-
decoded_string = code128_to_latin1(points.pack('C*'))
|
445
|
+
decoded_string = code128_to_latin1(points.pack('C*'), options)
|
443
446
|
|
444
447
|
Code128.new(decoded_string, options)
|
445
448
|
end
|
@@ -456,11 +459,26 @@ module Barcode1DTools
|
|
456
459
|
@encoded_string = value
|
457
460
|
@value = self.class.code128_to_latin1(value, options)
|
458
461
|
else
|
459
|
-
|
462
|
+
if value.is_a?(Array)
|
463
|
+
@value = value
|
464
|
+
else
|
465
|
+
@value = [value.to_s]
|
466
|
+
end
|
460
467
|
# In ruby 1.9, change to Latin-1 if it's in another encoding.
|
461
468
|
# Really, the caller needs to handle this.
|
462
|
-
if RUBY_VERSION >= "1.9"
|
463
|
-
value = value.
|
469
|
+
if RUBY_VERSION >= "1.9"
|
470
|
+
@value = @value.collect do |item|
|
471
|
+
if item.is_a?(Symbol)
|
472
|
+
item
|
473
|
+
else
|
474
|
+
item = item.to_s
|
475
|
+
if ['US-ASCII','ISO-8859-1'].include?(item.encoding)
|
476
|
+
item
|
477
|
+
else
|
478
|
+
item.encode('ISO-8859-1')
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
464
482
|
end
|
465
483
|
raise UnencodableCharactersError unless self.class.can_encode?(value)
|
466
484
|
@encoded_string = self.class.latin1_to_code128(@value, options)
|
@@ -21,10 +21,10 @@ class Barcode1DToolsCode128Test < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
def random_x_character_latin1_string(x)
|
23
23
|
str=(1..x).collect { rand(256) }.pack('C*')
|
24
|
-
if RUBY_VERSION
|
25
|
-
str.force_encoding('ISO-8859-1')
|
26
|
-
else
|
24
|
+
if RUBY_VERSION < "1.9"
|
27
25
|
str
|
26
|
+
else
|
27
|
+
str.force_encoding('ISO-8859-1')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -54,7 +54,7 @@ class Barcode1DToolsCode128Test < Test::Unit::TestCase
|
|
54
54
|
|
55
55
|
def test_attr_readers
|
56
56
|
c128 = Barcode1DTools::Code128.new('Hello!')
|
57
|
-
assert_equal 'Hello!', c128.value
|
57
|
+
assert_equal ['Hello!'], c128.value
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_decode_error
|
@@ -73,4 +73,14 @@ class Barcode1DToolsCode128Test < Test::Unit::TestCase
|
|
73
73
|
c1284 = Barcode1DTools::Code128.decode(c128.rle.reverse)
|
74
74
|
assert_equal c128.value, c1284.value
|
75
75
|
end
|
76
|
+
|
77
|
+
def test_serious_decoding
|
78
|
+
random_c128_str = random_crazy_code128_value(rand(5) + 10)
|
79
|
+
c128 = Barcode1DTools::Code128.new(random_c128_str, :no_latin1 => true)
|
80
|
+
c1282 = Barcode1DTools::Code128.decode(c128.rle, :no_latin1 => true)
|
81
|
+
assert_equal c128.value, c1282.value
|
82
|
+
# Should also work in reverse
|
83
|
+
c1284 = Barcode1DTools::Code128.decode(c128.rle.reverse, :no_latin1 => true)
|
84
|
+
assert_equal c128.value, c1284.value
|
85
|
+
end
|
76
86
|
end
|
metadata
CHANGED
@@ -1,42 +1,29 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcode1dtools
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.9.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 9
|
10
|
-
- 0
|
11
|
-
version: 0.9.9.0
|
12
6
|
platform: ruby
|
13
|
-
authors:
|
7
|
+
authors:
|
14
8
|
- Michael Chaney
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
date: 2012-09-22 00:00:00 -05:00
|
20
|
-
default_executable:
|
12
|
+
date: 2012-09-22 00:00:00.000000000Z
|
21
13
|
dependencies: []
|
22
|
-
|
23
|
-
|
24
|
-
\t
|
25
|
-
|
26
|
-
|
27
|
-
\t
|
28
|
-
\t
|
29
|
-
|
30
|
-
\t only generates and decodes the patterns; actual display or reading\n\
|
31
|
-
\t from a device must be implemented by the programmer.\n"
|
14
|
+
description: ! "\t Barcode1D is a small library for handling many kinds of\n\t 1-dimensional
|
15
|
+
barcodes. Currently implemented are Code 128, Code 3\n\t of 9, Code 93, Code 11,
|
16
|
+
Codabar, Interleaved 2 of 5, COOP 2 of 5,\n\t Matrix 2 of 5, Industrial 2 of 5,
|
17
|
+
IATA 2 of 5, PostNet, Plessey, MSI\n\t (Modified Plessey), EAN-13, EAN-8, UPC-A,
|
18
|
+
UPC-E, UPC Supplemental 2,\n\t and UPC Supplemental 5. Patterns are created in
|
19
|
+
either a simple\n\t format of bars and spaces or as a run-length encoded string.
|
20
|
+
\ This\n\t only generates and decodes the patterns; actual display or reading\n\t
|
21
|
+
from a device must be implemented by the programmer.\n"
|
32
22
|
email: mdchaney@michaelchaney.com
|
33
23
|
executables: []
|
34
|
-
|
35
24
|
extensions: []
|
36
|
-
|
37
25
|
extra_rdoc_files: []
|
38
|
-
|
39
|
-
files:
|
26
|
+
files:
|
40
27
|
- lib/barcode1dtools/codabar.rb
|
41
28
|
- lib/barcode1dtools/code11.rb
|
42
29
|
- lib/barcode1dtools/code128.rb
|
@@ -78,44 +65,33 @@ files:
|
|
78
65
|
- test/test_barcode1dupce.rb
|
79
66
|
- test/test_barcode1dupcsupp2.rb
|
80
67
|
- test/test_barcode1dupcsupp5.rb
|
81
|
-
has_rdoc: true
|
82
68
|
homepage: http://rubygems.org/gems/barcode1dtools
|
83
|
-
licenses:
|
69
|
+
licenses:
|
84
70
|
- MIT
|
85
71
|
- GPL-2
|
86
72
|
post_install_message:
|
87
73
|
rdoc_options: []
|
88
|
-
|
89
|
-
require_paths:
|
74
|
+
require_paths:
|
90
75
|
- lib
|
91
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
77
|
none: false
|
93
|
-
requirements:
|
94
|
-
- -
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
hash: 59
|
97
|
-
segments:
|
98
|
-
- 1
|
99
|
-
- 8
|
100
|
-
- 6
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
101
81
|
version: 1.8.6
|
102
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
83
|
none: false
|
104
|
-
requirements:
|
105
|
-
- -
|
106
|
-
- !ruby/object:Gem::Version
|
107
|
-
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
version: "0"
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
111
88
|
requirements: []
|
112
|
-
|
113
89
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.10
|
115
91
|
signing_key:
|
116
92
|
specification_version: 3
|
117
93
|
summary: Pattern generators for 1D barcodes
|
118
|
-
test_files:
|
94
|
+
test_files:
|
119
95
|
- test/test_barcode1d.rb
|
120
96
|
- test/test_barcode1dcodabar.rb
|
121
97
|
- test/test_barcode1dcode11.rb
|