barcodes 0.0.1 → 0.0.2

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.
Files changed (63) hide show
  1. data/Gemfile +6 -0
  2. data/README.md +24 -24
  3. data/Rakefile +6 -0
  4. data/barcodes.gemspec +6 -0
  5. data/lib/barcodes.rb +52 -0
  6. data/lib/barcodes/exec.rb +52 -31
  7. data/lib/barcodes/renderer.rb +6 -0
  8. data/lib/barcodes/renderer/ascii.rb +7 -0
  9. data/lib/barcodes/renderer/pdf.rb +6 -0
  10. data/lib/barcodes/symbology.rb +6 -0
  11. data/lib/barcodes/symbology/base.rb +55 -15
  12. data/lib/barcodes/symbology/codabar.rb +23 -0
  13. data/lib/barcodes/symbology/code11.rb +18 -0
  14. data/lib/barcodes/symbology/code128.rb +44 -5
  15. data/lib/barcodes/symbology/code39.rb +21 -0
  16. data/lib/barcodes/symbology/code39extended.rb +12 -0
  17. data/lib/barcodes/symbology/code39extendedmod43.rb +14 -0
  18. data/lib/barcodes/symbology/code39mod43.rb +14 -0
  19. data/lib/barcodes/symbology/code93.rb +23 -0
  20. data/lib/barcodes/symbology/code93extended.rb +17 -1
  21. data/lib/barcodes/symbology/ean.rb +28 -1
  22. data/lib/barcodes/symbology/ean13.rb +17 -0
  23. data/lib/barcodes/symbology/ean8.rb +18 -0
  24. data/lib/barcodes/symbology/interleaved2of5.rb +18 -0
  25. data/lib/barcodes/symbology/interleaved2of5mod10.rb +14 -0
  26. data/lib/barcodes/symbology/msi.rb +16 -0
  27. data/lib/barcodes/symbology/msimod10.rb +14 -0
  28. data/lib/barcodes/symbology/msimod11.rb +14 -0
  29. data/lib/barcodes/symbology/planet.rb +24 -1
  30. data/lib/barcodes/symbology/postnet.rb +24 -1
  31. data/lib/barcodes/symbology/standard2of5.rb +16 -0
  32. data/lib/barcodes/symbology/standard2of5mod10.rb +14 -0
  33. data/lib/barcodes/symbology/upca.rb +16 -0
  34. data/lib/barcodes/version.rb +9 -1
  35. data/spec/barcodes/exec_spec.rb +7 -1
  36. data/spec/barcodes/renderer/ascii_spec.rb +6 -0
  37. data/spec/barcodes/renderer/pdf_spec.rb +6 -0
  38. data/spec/barcodes/symbology/base_spec.rb +6 -0
  39. data/spec/barcodes/symbology/codabar_spec.rb +6 -0
  40. data/spec/barcodes/symbology/code11_spec.rb +6 -0
  41. data/spec/barcodes/symbology/code128_spec.rb +6 -0
  42. data/spec/barcodes/symbology/code39_spec.rb +6 -0
  43. data/spec/barcodes/symbology/code39extended_spec.rb +6 -0
  44. data/spec/barcodes/symbology/code39extendedmod43_spec.rb +6 -0
  45. data/spec/barcodes/symbology/code39mod43_spec.rb +6 -0
  46. data/spec/barcodes/symbology/code93_spec.rb +6 -0
  47. data/spec/barcodes/symbology/code93extended_spec.rb +6 -0
  48. data/spec/barcodes/symbology/ean13_spec.rb +6 -0
  49. data/spec/barcodes/symbology/ean8_spec.rb +6 -0
  50. data/spec/barcodes/symbology/ean_spec.rb +6 -0
  51. data/spec/barcodes/symbology/interleaved2of5_spec.rb +6 -0
  52. data/spec/barcodes/symbology/interleaved2of5mod10_spec.rb +6 -0
  53. data/spec/barcodes/symbology/msi_spec.rb +6 -0
  54. data/spec/barcodes/symbology/msimod10_spec.rb +6 -0
  55. data/spec/barcodes/symbology/msimod11_spec.rb +6 -0
  56. data/spec/barcodes/symbology/planet_spec.rb +6 -0
  57. data/spec/barcodes/symbology/postnet_spec.rb +6 -0
  58. data/spec/barcodes/symbology/standard2of5_spec.rb +6 -0
  59. data/spec/barcodes/symbology/standard2of5mod10_spec.rb +6 -0
  60. data/spec/barcodes/symbology/upca_spec.rb +6 -0
  61. data/spec/barcodes_spec.rb +6 -0
  62. data/spec/spec_helper.rb +6 -0
  63. metadata +8 -8
@@ -1,12 +1,33 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Codabar symbology.
13
+ # Codabar can encode the numbers 0-9 and the
14
+ # following symbols: -,$,:,/,.,+
15
+ #
16
+ # More info: http://en.wikipedia.org/wiki/Codabar
5
17
  class Codabar < Base
18
+
19
+ # Start character
20
+ attr_accessor :start_character
21
+
22
+ # Stop character
23
+ attr_accessor :stop_character
24
+
25
+ # Codabar character set (0-9,-,$,:,/,.,+)
6
26
  def self.charset
7
27
  ['0','1','2','3','4','5','6','7','8','9','-','$',':','/','.','+','A','B','C','D'].collect {|c| c.bytes.to_a[0] }
8
28
  end
9
29
 
30
+ # Codabar values set
10
31
  def self.valueset
11
32
  [
12
33
  '1010100110','1010110010','1010010110','110010101',
@@ -17,6 +38,7 @@ module Barcodes
17
38
  ]
18
39
  end
19
40
 
41
+ # Creates a new Codabar instance with given arguments.
20
42
  def initialize(args={})
21
43
  unless args.has_key? :start_character
22
44
  args[:start_character] = 'A'
@@ -28,6 +50,7 @@ module Barcodes
28
50
  super(args)
29
51
  end
30
52
 
53
+ # Start character + data + stop character
31
54
  def formatted_data
32
55
  @start_character + @data + @stop_character
33
56
  end
@@ -1,12 +1,26 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 11 symbology.
13
+ # Code 11 can encode the numbers 0-9 and the '-' dash symbol.
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Code_11
5
16
  class Code11 < Base
17
+
18
+ # The Code 11 character set 0-9 and the '-' dash symbol.
6
19
  def self.charset
7
20
  ['0','1','2','3','4','5','6','7','8','9','-','S'].collect {|c| c.bytes.to_a[0] }
8
21
  end
9
22
 
23
+ # The Code 11 values set
10
24
  def self.valueset
11
25
  [
12
26
  '1010110','11010110','10010110',
@@ -16,6 +30,7 @@ module Barcodes
16
30
  ]
17
31
  end
18
32
 
33
+ # Creates a new Code11 instance.
19
34
  def initialize(args={})
20
35
  super(args)
21
36
 
@@ -23,6 +38,7 @@ module Barcodes
23
38
  @stop_character = 'S'
24
39
  end
25
40
 
41
+ # Start character + data + checksum + stop character
26
42
  def formatted_data
27
43
  checksum = self.checksum
28
44
  unless checksum.nil?
@@ -30,6 +46,7 @@ module Barcodes
30
46
  end
31
47
  end
32
48
 
49
+ # Calculates the C and K checksums from the barcode data
33
50
  def checksum
34
51
  if valid?
35
52
  unless @data.length >= 10
@@ -45,6 +62,7 @@ module Barcodes
45
62
 
46
63
  protected
47
64
 
65
+ # Calculate the checksum with given data and weighting
48
66
  def _checksum(data, weight_max)
49
67
  sum = 0
50
68
  weight = 0
@@ -1,17 +1,44 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 128 symbology.
13
+ # Code 128 can encode all 128 ASCII characters using
14
+ # three different code sets.
15
+ #
16
+ # More info: http://en.wikipedia.org/wiki/Code_128
17
+ #
18
+ # Assigned to code sets where applicable are the following
19
+ # special characters representing Code 128 functions:
20
+ #
21
+ # * START_A - \xF4
22
+ # * START_B - \xF5
23
+ # * START_C - \xF6
24
+ # * CODE_A - \xF7
25
+ # * CODE_B - \xF8
26
+ # * CODE_C - \xF9
27
+ # * FNC1 - \xFA
28
+ # * FNC2 - \xFB
29
+ # * FNC3 - \xFC
30
+ # * FNC4 - \xFD
31
+ # * SHIFT - \xFE
32
+ # * STOP - \xFF
5
33
  class Code128 < Base
6
- # Assigned to codesets are the following special characters representing Code 128 functions
7
- # START_A - \xF4, START_B - \xF5, START_C - \xF6,
8
- # CODE_A - \xF7, CODE_B - \xF8, CODE_C - \xF9,
9
- # FNC1 - \xFA, FNC2 - \xFB, FNC3 - \xFC, FNC4 - \xFD,
10
- # SHIFT - \xFE, STOP - \xFF
34
+
35
+ # Code 128 uses three special character sets so this
36
+ # returns an empty array
11
37
  def self.charset
12
38
  [].collect {|c| c.bytes.to_a[0] }
13
39
  end
14
40
 
41
+ # Character code set A
15
42
  def self.charset_a
16
43
  [
17
44
  " ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/",
@@ -26,6 +53,7 @@ module Barcodes
26
53
  ].collect {|c| c.bytes.to_a[0] }
27
54
  end
28
55
 
56
+ # Character code set B
29
57
  def self.charset_b
30
58
  [
31
59
  " ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/",
@@ -38,6 +66,7 @@ module Barcodes
38
66
  ].collect {|c| c.bytes.to_a[0] }
39
67
  end
40
68
 
69
+ # Character code set C
41
70
  def self.charset_c
42
71
  [
43
72
  "00","01","02","03","04","05","06","07","08","09","10","11","12","13",
@@ -51,6 +80,7 @@ module Barcodes
51
80
  ].collect {|c| c.bytes.to_a.length > 1 ? c.bytes.to_a : c.bytes.to_a[0] }
52
81
  end
53
82
 
83
+ # Code 128 values set
54
84
  def self.valueset
55
85
  [
56
86
  "11011001100","11001101100","11001100110","10010011000","10010001100",
@@ -78,10 +108,12 @@ module Barcodes
78
108
  ]
79
109
  end
80
110
 
111
+ # Data + checksum + stop character
81
112
  def formatted_data
82
113
  self._prepared_data + self.checksum + "\xFF"
83
114
  end
84
115
 
116
+ # Data encoded as 1's and 0's using three code sets
85
117
  def encoded_data
86
118
  if self.valid?
87
119
  encoded_data = ""
@@ -141,6 +173,7 @@ module Barcodes
141
173
  end
142
174
  end
143
175
 
176
+ # Calculates the checksum using barcode data
144
177
  def checksum
145
178
  if valid?
146
179
  sum = 0
@@ -204,6 +237,7 @@ module Barcodes
204
237
  end
205
238
  end
206
239
 
240
+ # Validates the data
207
241
  def valid?
208
242
  valid = @data.length > 0 ? true : false
209
243
 
@@ -219,6 +253,8 @@ module Barcodes
219
253
 
220
254
  protected
221
255
 
256
+ # Inspects barcode data and determines the best character sets to use
257
+ # for provided data
222
258
  def _prepared_data
223
259
  start = "\xF5"
224
260
  charset = "B"
@@ -290,10 +326,13 @@ module Barcodes
290
326
  return data
291
327
  end
292
328
 
329
+ # Returns nil due to Code 128 using special character sets
293
330
  def _encode_character(character)
294
331
  return nil
295
332
  end
296
333
 
334
+ # Encodes a single character (as ASCII integer) using given
335
+ # character set
297
336
  def _encode_character_in_charset(character, charset)
298
337
  case charset
299
338
  when 'A'
@@ -1,8 +1,23 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 39 symbology.
13
+ # Code 39 can encode the numbers 0-9 and all capital
14
+ # letters along with the following symbols: ' ','-',
15
+ # '.','$','/','+','%','*'
16
+ #
17
+ # More info: http://en.wikipedia.org/wiki/Code_39
5
18
  class Code39 < Base
19
+
20
+ # The Code 39 character set
6
21
  def self.charset
7
22
  [
8
23
  '0','1','2','3','4','5','6','7','8','9',
@@ -13,6 +28,7 @@ module Barcodes
13
28
  ].collect {|c| c.bytes.to_a[0] }
14
29
  end
15
30
 
31
+ # The Code 39 values set
16
32
  def self.valueset
17
33
  [
18
34
  "1010011011010","1101001010110","1011001010110","1101100101010",
@@ -29,6 +45,7 @@ module Barcodes
29
45
  ]
30
46
  end
31
47
 
48
+ # Creates a new Code39 instance.
32
49
  def initialize(args={})
33
50
  super(args)
34
51
 
@@ -36,10 +53,14 @@ module Barcodes
36
53
  @stop_character = '*'
37
54
  end
38
55
 
56
+ # Code 39 includes the start and stop symbols in
57
+ # the caption so caption_data is overridden here
58
+ # to return the formatted data string
39
59
  def caption_data
40
60
  self.formatted_data
41
61
  end
42
62
 
63
+ # Start character + data + stop character
43
64
  def formatted_data
44
65
  @start_character + @data + @stop_character
45
66
  end
@@ -1,11 +1,23 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/code39'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 39 Extended symbology.
13
+ # Code 39 Extended can encode all standard ASCII characters.
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Code_39
5
16
  class Code39Extended < Code39
6
17
 
7
18
  protected
8
19
 
20
+ # Encodes given character (as ASCII integer) into 1's and 0's
9
21
  def _encode_character(character)
10
22
  unless (character == 36 || character == 37 || character == 43)
11
23
  unless super(character).nil?
@@ -1,12 +1,25 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/code39extended'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # Modulo 43 checksum version of Code 39 Extended
13
+ #
14
+ # More info: http://en.wikipedia.org/wiki/Code_39
5
15
  class Code39ExtendedMod43 < Code39Extended
16
+
17
+ # Returns caption data without checksum
6
18
  def caption_data
7
19
  @start_character + @data + @stop_character
8
20
  end
9
21
 
22
+ # Start character + data + checksum + stop character
10
23
  def formatted_data
11
24
  checksum = self.checksum
12
25
  unless checksum.nil?
@@ -14,6 +27,7 @@ module Barcodes
14
27
  end
15
28
  end
16
29
 
30
+ # Calculates the checksum using the provided data
17
31
  def checksum
18
32
  if valid?
19
33
  sum = 0
@@ -1,12 +1,25 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/code39'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # Modulo 43 checksum version of Code 39
13
+ #
14
+ # More info: http://en.wikipedia.org/wiki/Code_39
5
15
  class Code39Mod43 < Code39
16
+
17
+ # Returns caption data without checksum
6
18
  def caption_data
7
19
  @start_character + @data + @stop_character
8
20
  end
9
21
 
22
+ # Start character + data + checksum + stop character
10
23
  def formatted_data
11
24
  checksum = self.checksum
12
25
  unless checksum.nil?
@@ -14,6 +27,7 @@ module Barcodes
14
27
  end
15
28
  end
16
29
 
30
+ # Calculates the checksum using the provided data
17
31
  def checksum
18
32
  if self.valid?
19
33
  sum = 0
@@ -1,8 +1,23 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/base'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 93 symbology.
13
+ # Code 93 can encode the characters 0-9 and A-Z along
14
+ # with the following characters: "-","."," ","$",
15
+ # "/","+","%","*"
16
+ #
17
+ # More info: http://en.wikipedia.org/wiki/Code_93
5
18
  class Code93 < Base
19
+
20
+ # The Code 93 character set
6
21
  def self.charset
7
22
  [
8
23
  "0","1","2","3","4","5","6","7","8","9",
@@ -13,6 +28,7 @@ module Barcodes
13
28
  ].collect {|c| c.bytes.to_a[0] }
14
29
  end
15
30
 
31
+ # The Code 93 values set
16
32
  def self.valueset
17
33
  [
18
34
  "100010100","101001000","101000100","101000010",
@@ -30,6 +46,7 @@ module Barcodes
30
46
  ]
31
47
  end
32
48
 
49
+ # Creates a new Code93 instance.
33
50
  def initialize(args={})
34
51
  super(args)
35
52
 
@@ -37,10 +54,14 @@ module Barcodes
37
54
  @stop_character = '*'
38
55
  end
39
56
 
57
+ # Code 39 includes the start and stop symbols in
58
+ # the caption so caption_data is overridden here
59
+ # to return the formatted data string
40
60
  def caption_data
41
61
  @start_character + @data + @stop_character
42
62
  end
43
63
 
64
+ # Start character + data + checksum + stop character
44
65
  def formatted_data
45
66
  checksum = self.checksum
46
67
  unless checksum.nil?
@@ -48,6 +69,7 @@ module Barcodes
48
69
  end
49
70
  end
50
71
 
72
+ # Calculates the C and K checksum values
51
73
  def checksum
52
74
  if self.valid?
53
75
  c_value = self._checksum(@data, 20)
@@ -58,6 +80,7 @@ module Barcodes
58
80
 
59
81
  protected
60
82
 
83
+ # Calculates the checksum with given data and given weighting
61
84
  def _checksum(data, weight_max)
62
85
  sum = 0
63
86
  weight = 1
@@ -1,9 +1,21 @@
1
+ # Barcodes is a RubyGem for creating and rendering common barcode symbologies.
2
+ #
3
+ # Author:: Aaron Wright (mailto:acwrightdesign@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Infinite Token LLC
5
+ # License:: MIT License
6
+
1
7
  require 'barcodes/symbology/code93'
2
8
 
3
9
  module Barcodes
4
10
  module Symbology
11
+
12
+ # This class represents the Code 93 Extended symbology.
13
+ # Code 93 Extended can encode all standard ASCII characters.
14
+ #
15
+ # More info: http://en.wikipedia.org/wiki/Code_93
5
16
  class Code93Extended < Code93
6
17
 
18
+ # Start character + data + checksum + stop character
7
19
  def formatted_data
8
20
  checksum = self.checksum
9
21
  unless checksum.nil?
@@ -11,6 +23,7 @@ module Barcodes
11
23
  end
12
24
  end
13
25
 
26
+ # Calculates the C and K checksum values
14
27
  def checksum
15
28
  if self.valid?
16
29
  data = self._data
@@ -20,12 +33,15 @@ module Barcodes
20
33
  end
21
34
  end
22
35
 
36
+ # Validates the data
23
37
  def valid?
24
38
  return !self._data.nil?
25
39
  end
26
40
 
27
41
  protected
28
-
42
+
43
+ # Format the data string by adding shift characters when
44
+ # applicable
29
45
  def _data
30
46
  _data = ''
31
47
  self.data.each_byte do |char|