barcodes 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -117,7 +117,7 @@ module Barcodes
117
117
  def encoded_data
118
118
  if self.valid?
119
119
  encoded_data = ""
120
- charset = 'B'
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 = 0
181
- charset = self.class.charset_b
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 = "\xF5"
260
- charset = "B"
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], 'B').nil?
266
+ elsif self._encode_character_in_charset(@data.bytes.to_a[0], 'A').nil?
268
267
  start = "\xF4"
269
- charset = "A"
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 += 37
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 < 9
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)
@@ -33,10 +33,6 @@ module Barcodes
33
33
  # is valid.
34
34
  # Data length must be exactly 12 digits
35
35
  def valid?
36
- unless super
37
- return false
38
- end
39
-
40
36
  return self.data.length == 12 ? true : false
41
37
  end
42
38
  end
@@ -57,10 +57,6 @@ module Barcodes
57
57
  # is valid.
58
58
  # Data length must be exactly 7 digits
59
59
  def valid?
60
- unless super
61
- return false
62
- end
63
-
64
60
  return self.data.length == 7 ? true : false
65
61
  end
66
62
  end
@@ -32,10 +32,6 @@ module Barcodes
32
32
  # Validates barcode using provided data
33
33
  # Data length must be 11 digits
34
34
  def valid?
35
- unless super
36
- return false
37
- end
38
-
39
35
  return self.data.length == 11 ? true : false
40
36
  end
41
37
  end
@@ -7,5 +7,5 @@
7
7
  #
8
8
  module Barcodes
9
9
  # Returns the current version
10
- VERSION = "0.0.8"
10
+ VERSION = "0.0.9"
11
11
  end
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.8
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-09 00:00:00.000000000 Z
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: 2449543112695884556
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: 2449543112695884556
160
+ hash: -2445939698446787454
161
161
  requirements: []
162
162
  rubyforge_project: barcodes
163
163
  rubygems_version: 1.8.24