barcodes 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/barcodes/symbology/code128.rb +7 -8
- data/lib/barcodes/symbology/code93.rb +12 -12
- data/lib/barcodes/symbology/ean.rb +1 -13
- data/lib/barcodes/symbology/ean13.rb +0 -4
- data/lib/barcodes/symbology/ean8.rb +0 -4
- data/lib/barcodes/symbology/upca.rb +0 -4
- data/lib/barcodes/version.rb +1 -1
- metadata +4 -4
@@ -117,7 +117,7 @@ module Barcodes
|
|
117
117
|
def encoded_data
|
118
118
|
if self.valid?
|
119
119
|
encoded_data = ""
|
120
|
-
charset = '
|
120
|
+
charset = 'A'
|
121
121
|
char_c = nil
|
122
122
|
self.formatted_data.each_byte do |char|
|
123
123
|
if char == "\xF4".bytes.to_a[0] || char == "\xF5".bytes.to_a[0] || char == "\xF6".bytes.to_a[0]
|
@@ -177,13 +177,12 @@ module Barcodes
|
|
177
177
|
def checksum
|
178
178
|
if valid?
|
179
179
|
sum = 0
|
180
|
-
index =
|
181
|
-
charset = self.class.
|
180
|
+
index = 1
|
181
|
+
charset = self.class.charset_a
|
182
182
|
char_c = nil
|
183
183
|
self._prepared_data.each_byte do |char|
|
184
184
|
if char == "\xF4".bytes.to_a[0] || char == "\xF5".bytes.to_a[0] || char == "\xF6".bytes.to_a[0]
|
185
185
|
sum += self.class.charset_a.index(char) if self.class.charset_a.include?(char)
|
186
|
-
index += 1
|
187
186
|
|
188
187
|
case char
|
189
188
|
when "\xF4".bytes.to_a[0]
|
@@ -256,17 +255,17 @@ module Barcodes
|
|
256
255
|
# Inspects barcode data and determines the best character sets to use
|
257
256
|
# for provided data
|
258
257
|
def _prepared_data
|
259
|
-
start = "\
|
260
|
-
charset = "
|
258
|
+
start = "\xF4"
|
259
|
+
charset = "A"
|
261
260
|
data = ""
|
262
261
|
cursor = 0
|
263
262
|
|
264
263
|
if /^[\d]{4,}/ === @data
|
265
264
|
start = "\xF6"
|
266
265
|
charset = "C"
|
267
|
-
elsif self._encode_character_in_charset(@data.bytes.to_a[0], '
|
266
|
+
elsif self._encode_character_in_charset(@data.bytes.to_a[0], 'A').nil?
|
268
267
|
start = "\xF4"
|
269
|
-
charset = "
|
268
|
+
charset = "B"
|
270
269
|
end
|
271
270
|
data += start
|
272
271
|
|
@@ -88,35 +88,35 @@ module Barcodes
|
|
88
88
|
if char == 255 || char == 254 || char == 253 || char == 252
|
89
89
|
case char
|
90
90
|
when 252
|
91
|
-
sum += 43
|
91
|
+
sum += weight * 43
|
92
92
|
when 253
|
93
|
-
sum += 44
|
93
|
+
sum += weight * 44
|
94
94
|
when 254
|
95
|
-
sum += 45
|
95
|
+
sum += weight * 45
|
96
96
|
when 255
|
97
|
-
sum += 46
|
97
|
+
sum += weight * 46
|
98
98
|
end
|
99
99
|
else
|
100
100
|
if ('0'..'9').include? char.chr
|
101
101
|
sum += weight * char.chr.to_i
|
102
102
|
elsif ('A'..'Z').include? char.chr
|
103
|
-
sum += ('A'..'Z').to_a.index(char.chr) + 10
|
103
|
+
sum += weight * (('A'..'Z').to_a.index(char.chr) + 10)
|
104
104
|
else
|
105
105
|
case char.chr
|
106
106
|
when '-'
|
107
|
-
sum += 36
|
107
|
+
sum += weight * 36
|
108
108
|
when '.'
|
109
|
-
sum +=
|
109
|
+
sum += weight * 837
|
110
110
|
when ' '
|
111
|
-
sum += 38
|
111
|
+
sum += weight * 38
|
112
112
|
when '$'
|
113
|
-
sum += 39
|
113
|
+
sum += weight * 39
|
114
114
|
when '/'
|
115
|
-
sum += 40
|
115
|
+
sum += weight * 40
|
116
116
|
when '+'
|
117
|
-
sum += 41
|
117
|
+
sum += weight * 41
|
118
118
|
when '%'
|
119
|
-
sum += 42
|
119
|
+
sum += weight * 42
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -88,7 +88,7 @@ module Barcodes
|
|
88
88
|
elsif char.chr == 'C'
|
89
89
|
encoded_data += "01010"
|
90
90
|
else
|
91
|
-
if index <
|
91
|
+
if index < 8
|
92
92
|
unless parity.nil?
|
93
93
|
encoded_data += self._encode_character_with_parity(char, parity[index - 2])
|
94
94
|
else
|
@@ -131,18 +131,6 @@ module Barcodes
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
# Validates barcode using provided data
|
135
|
-
def valid?
|
136
|
-
self.data.each_byte do |char|
|
137
|
-
if char.chr == 'S' || char.chr == 'C'
|
138
|
-
return false
|
139
|
-
end
|
140
|
-
unless self.class.charset.include? char
|
141
|
-
return false
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
134
|
protected
|
147
135
|
|
148
136
|
# Encodes a single given character (as ASCII integer) using the given parity (1,0)
|
data/lib/barcodes/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barcodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash:
|
151
|
+
hash: -2445939698446787454
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash:
|
160
|
+
hash: -2445939698446787454
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project: barcodes
|
163
163
|
rubygems_version: 1.8.24
|