barcodes 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,90 +15,109 @@ module Barcodes
15
15
  # More info: http://en.wikipedia.org/wiki/Code_39
16
16
  class Code39Extended < Code39
17
17
 
18
- protected
18
+ # Start character + prepared data + stop character
19
+ def formatted_data
20
+ @start_character + self._data + @stop_character
21
+ end
22
+
23
+ # Determines whether or not the barcode data to be encoded
24
+ # is valid.
25
+ def valid?
26
+ valid = self.data.length > 0 ? true : false
19
27
 
20
- # Encodes given character (as ASCII integer) into 1's and 0's
21
- def _encode_character(character)
22
- unless (character == 36 || character == 37 || character == 43)
23
- unless super(character).nil?
24
- return super(character)
28
+ self._data.each_byte do |char|
29
+ if self._encode_character(char).nil?
30
+ return false
25
31
  end
26
32
  end
33
+
34
+ return valid
35
+ end
36
+
37
+ #protected
38
+
39
+ # Returns prepared barcode data by replacing extended characters
40
+ def _data
41
+ prepared_data = ""
27
42
 
28
- case character
29
- when 0
30
- return super('%'.bytes.to_a[0]) + super('U'.bytes.to_a[0])
31
- when 1..26
32
- return super('$'.bytes.to_a[0]) + super((character.bytes.to_a[0] + 64))
33
- when 27..31
34
- return super('%'.bytes.to_a[0]) + super((character.bytes.to_a[0] + 38))
35
- when 127
36
- return super('%'.bytes.to_a[0]) + super('T'.bytes.to_a[0])
37
- when '!'.bytes.to_a[0]
38
- return super('/'.bytes.to_a[0]) + super('A'.bytes.to_a[0])
39
- when '"'.bytes.to_a[0]
40
- return super('/'.bytes.to_a[0]) + super('B'.bytes.to_a[0])
41
- when '#'.bytes.to_a[0]
42
- return super('/'.bytes.to_a[0]) + super('C'.bytes.to_a[0])
43
- when '$'.bytes.to_a[0]
44
- return super('/'.bytes.to_a[0]) + super('D'.bytes.to_a[0])
45
- when '%'.bytes.to_a[0]
46
- return super('/'.bytes.to_a[0]) + super('E'.bytes.to_a[0])
47
- when '&'.bytes.to_a[0]
48
- return super('/'.bytes.to_a[0]) + super('F'.bytes.to_a[0])
49
- when '\''.bytes.to_a[0]
50
- return super('/'.bytes.to_a[0]) + super('G'.bytes.to_a[0])
51
- when '('.bytes.to_a[0]
52
- return super('/'.bytes.to_a[0]) + super('H'.bytes.to_a[0])
53
- when ')'.bytes.to_a[0]
54
- return super('/'.bytes.to_a[0]) + super('I'.bytes.to_a[0])
55
- when '*'.bytes.to_a[0]
56
- return super('/'.bytes.to_a[0]) + super('J'.bytes.to_a[0])
57
- when '+'.bytes.to_a[0]
58
- return super('/'.bytes.to_a[0]) + super('K'.bytes.to_a[0])
59
- when ','.bytes.to_a[0]
60
- return super('/'.bytes.to_a[0]) + super('L'.bytes.to_a[0])
61
- when '/'.bytes.to_a[0]
62
- return super('/'.bytes.to_a[0]) + super('O'.bytes.to_a[0])
63
- when ':'.bytes.to_a[0]
64
- return super('/'.bytes.to_a[0]) + super('Z'.bytes.to_a[0])
65
- when ';'.bytes.to_a[0]
66
- return super('%'.bytes.to_a[0]) + super('F'.bytes.to_a[0])
67
- when '<'.bytes.to_a[0]
68
- return super('%'.bytes.to_a[0]) + super('G'.bytes.to_a[0])
69
- when '='.bytes.to_a[0]
70
- return super('%'.bytes.to_a[0]) + super('H'.bytes.to_a[0])
71
- when '>'.bytes.to_a[0]
72
- return super('%'.bytes.to_a[0]) + super('I'.bytes.to_a[0])
73
- when '?'.bytes.to_a[0]
74
- return super('%'.bytes.to_a[0]) + super('J'.bytes.to_a[0])
75
- when '@'.bytes.to_a[0]
76
- return super('%'.bytes.to_a[0]) + super('V'.bytes.to_a[0])
77
- when '['.bytes.to_a[0]
78
- return super('%'.bytes.to_a[0]) + super('K'.bytes.to_a[0])
79
- when '\\'.bytes.to_a[0]
80
- return super('%'.bytes.to_a[0]) + super('L'.bytes.to_a[0])
81
- when ']'.bytes.to_a[0]
82
- return super('%'.bytes.to_a[0]) + super('M'.bytes.to_a[0])
83
- when '^'.bytes.to_a[0]
84
- return super('%'.bytes.to_a[0]) + super('N'.bytes.to_a[0])
85
- when '_'.bytes.to_a[0]
86
- return super('%'.bytes.to_a[0]) + super('0'.bytes.to_a[0])
87
- when '`'.bytes.to_a[0]
88
- return super('%'.bytes.to_a[0]) + super('W'.bytes.to_a[0])
89
- when 97..122
90
- return super('+'.bytes.to_a[0]) + super(character.chr.upcase.bytes.to_a[0])
91
- when '{'.bytes.to_a[0]
92
- return super('%'.bytes.to_a[0]) + super('P'.bytes.to_a[0])
93
- when '|'.bytes.to_a[0]
94
- return super('%'.bytes.to_a[0]) + super('Q'.bytes.to_a[0])
95
- when '}'.bytes.to_a[0]
96
- return super('%'.bytes.to_a[0]) + super('R'.bytes.to_a[0])
97
- when '~'.bytes.to_a[0]
98
- return super('%'.bytes.to_a[0]) + super('S'.bytes.to_a[0])
99
- else
100
- return nil
43
+ self.data.each_byte do |character|
44
+ case character
45
+ when 0
46
+ prepared_data += '%' + 'U'
47
+ when 1..26
48
+ prepared_data += '$' + (character + 64).chr
49
+ when 27..31
50
+ prepared_data += '%' + (character + 38).chr
51
+ when 127
52
+ prepared_data += '%' + 'T'
53
+ when '!'.bytes.to_a[0]
54
+ prepared_data += '/' + 'A'
55
+ when '"'.bytes.to_a[0]
56
+ prepared_data += '/' + 'B'
57
+ when '#'.bytes.to_a[0]
58
+ prepared_data += '/' + 'C'
59
+ when '$'.bytes.to_a[0]
60
+ prepared_data += '/' + 'D'
61
+ when '%'.bytes.to_a[0]
62
+ prepared_data += '/' + 'E'
63
+ when '&'.bytes.to_a[0]
64
+ prepared_data += '/' + 'F'
65
+ when '\''.bytes.to_a[0]
66
+ prepared_data += '/' + 'G'
67
+ when '('.bytes.to_a[0]
68
+ prepared_data += '/' + 'H'
69
+ when ')'.bytes.to_a[0]
70
+ prepared_data += '/' + 'I'
71
+ when '*'.bytes.to_a[0]
72
+ prepared_data += '/' + 'J'
73
+ when '+'.bytes.to_a[0]
74
+ prepared_data += '/' + 'K'
75
+ when ','.bytes.to_a[0]
76
+ prepared_data += '/' + 'L'
77
+ when '/'.bytes.to_a[0]
78
+ prepared_data += '/' + 'O'
79
+ when ':'.bytes.to_a[0]
80
+ prepared_data += '/' + 'Z'
81
+ when ';'.bytes.to_a[0]
82
+ prepared_data += '%' + 'F'
83
+ when '<'.bytes.to_a[0]
84
+ prepared_data += '%' + 'G'
85
+ when '='.bytes.to_a[0]
86
+ prepared_data += '%' + 'H'
87
+ when '>'.bytes.to_a[0]
88
+ prepared_data += '%' + 'I'
89
+ when '?'.bytes.to_a[0]
90
+ prepared_data += '%' + 'J'
91
+ when '@'.bytes.to_a[0]
92
+ prepared_data += '%' + 'V'
93
+ when '['.bytes.to_a[0]
94
+ prepared_data += '%' + 'K'
95
+ when '\\'.bytes.to_a[0]
96
+ prepared_data += '%' + 'L'
97
+ when ']'.bytes.to_a[0]
98
+ prepared_data += '%' + 'M'
99
+ when '^'.bytes.to_a[0]
100
+ prepared_data += '%' + 'N'
101
+ when '_'.bytes.to_a[0]
102
+ prepared_data += '%' + '0'
103
+ when '`'.bytes.to_a[0]
104
+ prepared_data += '%' + 'W'
105
+ when 97..122
106
+ prepared_data += '+' + character.chr.upcase
107
+ when '{'.bytes.to_a[0]
108
+ prepared_data += '%' + 'P'
109
+ when '|'.bytes.to_a[0]
110
+ prepared_data += '%' + 'Q'
111
+ when '}'.bytes.to_a[0]
112
+ prepared_data += '%' + 'R'
113
+ when '~'.bytes.to_a[0]
114
+ prepared_data += '%' + 'S'
115
+ else
116
+ prepared_data += character.chr
117
+ end
101
118
  end
119
+
120
+ return prepared_data
102
121
  end
103
122
  end
104
123
  end
@@ -19,11 +19,11 @@ module Barcodes
19
19
  @start_character + @data + @stop_character
20
20
  end
21
21
 
22
- # Start character + data + checksum + stop character
22
+ # Start character + prepared data + checksum + stop character
23
23
  def formatted_data
24
24
  checksum = self.checksum
25
25
  unless checksum.nil?
26
- @start_character + @data + checksum + @stop_character
26
+ @start_character + self._data + checksum + @stop_character
27
27
  end
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ module Barcodes
31
31
  def checksum
32
32
  if valid?
33
33
  sum = 0
34
- self.data.each_char do |char|
34
+ self._data.each_char do |char|
35
35
  if ('0'..'9').include? char
36
36
  sum += char.to_i
37
37
  elsif ('A'..'Z').include? char
@@ -7,5 +7,5 @@
7
7
  #
8
8
  module Barcodes
9
9
  # Returns the current version
10
- VERSION = "0.0.7"
10
+ VERSION = "0.0.8"
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.7
4
+ version: 0.0.8
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-05 00:00:00.000000000 Z
12
+ date: 2012-09-09 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: 187278537168354622
151
+ hash: 2449543112695884556
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: 187278537168354622
160
+ hash: 2449543112695884556
161
161
  requirements: []
162
162
  rubyforge_project: barcodes
163
163
  rubygems_version: 1.8.24