barcodes 0.0.1

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 (68) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +22 -0
  6. data/README.md +107 -0
  7. data/Rakefile +11 -0
  8. data/barcodes.gemspec +24 -0
  9. data/bin/barcodes +6 -0
  10. data/lib/barcodes.rb +63 -0
  11. data/lib/barcodes/exec.rb +74 -0
  12. data/lib/barcodes/renderer.rb +9 -0
  13. data/lib/barcodes/renderer/ascii.rb +199 -0
  14. data/lib/barcodes/renderer/pdf.rb +257 -0
  15. data/lib/barcodes/symbology.rb +47 -0
  16. data/lib/barcodes/symbology/base.rb +103 -0
  17. data/lib/barcodes/symbology/codabar.rb +36 -0
  18. data/lib/barcodes/symbology/code11.rb +74 -0
  19. data/lib/barcodes/symbology/code128.rb +317 -0
  20. data/lib/barcodes/symbology/code39.rb +48 -0
  21. data/lib/barcodes/symbology/code39extended.rb +93 -0
  22. data/lib/barcodes/symbology/code39extendedmod43.rb +73 -0
  23. data/lib/barcodes/symbology/code39mod43.rb +73 -0
  24. data/lib/barcodes/symbology/code93.rb +142 -0
  25. data/lib/barcodes/symbology/code93extended.rb +116 -0
  26. data/lib/barcodes/symbology/ean.rb +149 -0
  27. data/lib/barcodes/symbology/ean13.rb +27 -0
  28. data/lib/barcodes/symbology/ean8.rb +50 -0
  29. data/lib/barcodes/symbology/interleaved2of5.rb +30 -0
  30. data/lib/barcodes/symbology/interleaved2of5mod10.rb +40 -0
  31. data/lib/barcodes/symbology/msi.rb +30 -0
  32. data/lib/barcodes/symbology/msimod10.rb +50 -0
  33. data/lib/barcodes/symbology/msimod11.rb +37 -0
  34. data/lib/barcodes/symbology/planet.rb +83 -0
  35. data/lib/barcodes/symbology/postnet.rb +83 -0
  36. data/lib/barcodes/symbology/standard2of5.rb +30 -0
  37. data/lib/barcodes/symbology/standard2of5mod10.rb +40 -0
  38. data/lib/barcodes/symbology/upca.rb +27 -0
  39. data/lib/barcodes/version.rb +3 -0
  40. data/spec/barcodes/exec_spec.rb +14 -0
  41. data/spec/barcodes/renderer/ascii_spec.rb +12 -0
  42. data/spec/barcodes/renderer/pdf_spec.rb +12 -0
  43. data/spec/barcodes/symbology/base_spec.rb +8 -0
  44. data/spec/barcodes/symbology/codabar_spec.rb +8 -0
  45. data/spec/barcodes/symbology/code11_spec.rb +8 -0
  46. data/spec/barcodes/symbology/code128_spec.rb +8 -0
  47. data/spec/barcodes/symbology/code39_spec.rb +8 -0
  48. data/spec/barcodes/symbology/code39extended_spec.rb +8 -0
  49. data/spec/barcodes/symbology/code39extendedmod43_spec.rb +8 -0
  50. data/spec/barcodes/symbology/code39mod43_spec.rb +8 -0
  51. data/spec/barcodes/symbology/code93_spec.rb +8 -0
  52. data/spec/barcodes/symbology/code93extended_spec.rb +8 -0
  53. data/spec/barcodes/symbology/ean13_spec.rb +8 -0
  54. data/spec/barcodes/symbology/ean8_spec.rb +8 -0
  55. data/spec/barcodes/symbology/ean_spec.rb +8 -0
  56. data/spec/barcodes/symbology/interleaved2of5_spec.rb +8 -0
  57. data/spec/barcodes/symbology/interleaved2of5mod10_spec.rb +8 -0
  58. data/spec/barcodes/symbology/msi_spec.rb +8 -0
  59. data/spec/barcodes/symbology/msimod10_spec.rb +8 -0
  60. data/spec/barcodes/symbology/msimod11_spec.rb +8 -0
  61. data/spec/barcodes/symbology/planet_spec.rb +8 -0
  62. data/spec/barcodes/symbology/postnet_spec.rb +8 -0
  63. data/spec/barcodes/symbology/standard2of5_spec.rb +8 -0
  64. data/spec/barcodes/symbology/standard2of5mod10_spec.rb +8 -0
  65. data/spec/barcodes/symbology/upca_spec.rb +8 -0
  66. data/spec/barcodes_spec.rb +27 -0
  67. data/spec/spec_helper.rb +17 -0
  68. metadata +174 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p290@barcodes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in labels.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Infinite Token LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ Barcodes
2
+ ========
3
+
4
+ Barcodes is a RubyGem for creating and rendering common barcode symbologies. Here are some of the current features:
5
+
6
+ * Many common symbologies to choose from
7
+ * PDF and ASCII rendering support
8
+ * Command line interface for rendering barcodes to console or file
9
+
10
+ Currently supported symbologies:
11
+
12
+ * Code 11
13
+ * Code 128
14
+ * Code 39
15
+ * Code 39 Mod 43
16
+ * Code 39 Extended
17
+ * Code 39 Extended Mod 43
18
+ * Code 93
19
+ * Code 93 Extended
20
+ * EAN8
21
+ * EAN13
22
+ * Interleaved 2 of 5
23
+ * Interleaved 2 of 5 Mod 10
24
+ * MSI
25
+ * MSI Mod 10
26
+ * MSI Mod 11
27
+ * PLANET
28
+ * POSTNET
29
+ * Standard 2 of 5
30
+ * Standard 2 of 5 Mod 10
31
+ * UPC-A
32
+
33
+ Installation
34
+ ------------
35
+
36
+ Barcodes is a RubyGem and can be installed using:
37
+
38
+ gem install barcodes
39
+
40
+ Usage
41
+ -----
42
+
43
+ If you want to create and render a barcode all in one step you can simply do the following:
44
+
45
+ Barcodes.render('Codabar', '/path/to/output.pdf', {:data => '12345'})
46
+
47
+ The output path can be left empty and the rendered output will be returned as a string.
48
+
49
+ By default Barcodes uses the PDF renderer. To use the ASCII renderer you would do the following:
50
+
51
+ Barcodes.render('Codabar', '/path/to/output.pdf', {:data => '12345'}, Barcodes::Renderer::Ascii)
52
+
53
+ You could also do this:
54
+
55
+ barcode = Barcodes.create('Postnet', {:data => '44555'})
56
+
57
+ pdf_renderer = Barcodes::Renderer::Pdf.new(barcode)
58
+ pdf_renderer.render('/path/to/output.pdf')
59
+
60
+ ascii_renderer = Barcodes::Renderer::Ascii.new(barcode)
61
+ ascii_renderer.render('/path/to/output.txt')
62
+
63
+ The following options (defaults shown below) are available for all barcode symbologies:
64
+
65
+ {
66
+ :data => '0123456789',
67
+ :start_character => '',
68
+ :stop_character => '',
69
+ :bar_width => 20, # in mils
70
+ :bar_height => 1000, # in mils
71
+ :alpha => 1.0,
72
+ :color => '000000',
73
+ :caption_height => 180, # in mils
74
+ :caption_size => 167, # in mils
75
+ :captioned => true,
76
+ }
77
+
78
+ Command Line
79
+ ------------
80
+
81
+ Barcodes also provides a command line tool for rendering barcodes:
82
+
83
+ $ barcodes -h
84
+ Usage: barcodes [OPTIONS] symbology target
85
+
86
+ -D, --data [DATA] The barcode data to encode (0123456789)
87
+ -s [START_CHARACTER], The barcode start character if applicable
88
+ --start_character
89
+ -e [STOP_CHARACTER], The barcode stop character if applicable
90
+ --stop_character
91
+ -W, --bar_width [BAR_WIDTH] The barcode bar width in mils (20)
92
+ -H, --bar_height [BAR_HEIGHT] The barcode bar height in mils (1000)
93
+ -c [CAPTION_HEIGHT], The barcode caption height in mils (180)
94
+ --caption_height
95
+ -p [CAPTION_SIZE], The caption font size in mils (167)
96
+ --caption_size
97
+ -A, --alpha [ALPHA] The barcode transparency (1.0)
98
+ -O, --color [COLOR] The barcode color in hex (000000)
99
+ -a, --captioned Render barcode caption (true)
100
+ -i, --ascii Render barcode as ASCII string (false)
101
+ -v, --version
102
+ -h, --help
103
+
104
+ License
105
+ -------
106
+
107
+ MIT License. See LICENSE file for details.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ namespace :barcodes do
7
+ desc "Start the console"
8
+ task :console do
9
+ sh("irb -rubygems -I lib -r barcodes.rb")
10
+ end
11
+ end
data/barcodes.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "barcodes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "barcodes"
7
+ s.version = Barcodes::VERSION
8
+ s.authors = ["Aaron Wright"]
9
+ s.email = ["acwrightdesign@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Barcode creation using Ruby!}
12
+ s.description = %q{Barcodes is a RubyGem for creating and rendering common barcode symbologies.}
13
+
14
+ s.rubyforge_project = "barcodes"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'rspec'
23
+ s.add_runtime_dependency 'prawn'
24
+ end
data/bin/barcodes ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'barcodes/exec'
5
+
6
+ Barcodes::Exec.new(ARGV).run
data/lib/barcodes.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'barcodes/version'
2
+ require 'barcodes/symbology'
3
+ require 'barcodes/renderer'
4
+
5
+ module Barcodes
6
+ class << self
7
+ def create(symbology, options={})
8
+ if Symbology::CODABAR.include? symbology
9
+ return Symbology::Codabar.new(options)
10
+ elsif Symbology::CODE_11.include? symbology
11
+ return Symbology::Code11.new(options)
12
+ elsif Symbology::CODE_39.include? symbology
13
+ return Symbology::Code39.new(options)
14
+ elsif Symbology::CODE_39_MOD_43.include? symbology
15
+ return Symbology::Code39Mod43.new(options)
16
+ elsif Symbology::CODE_39_EXTENDED.include? symbology
17
+ return Symbology::Code39Extended.new(options)
18
+ elsif Symbology::CODE_39_EXTENDED_MOD_43.include? symbology
19
+ return Symbology::Code39ExtendedMod43.new(options)
20
+ elsif Symbology::CODE_93.include? symbology
21
+ return Symbology::Code93.new(options)
22
+ elsif Symbology::CODE_93_EXTENDED.include? symbology
23
+ return Symbology::Code93Extended.new(options)
24
+ elsif Symbology::CODE_128.include? symbology
25
+ return Symbology::Code128.new(options)
26
+ elsif Symbology::EAN_8.include? symbology
27
+ return Symbology::Ean8.new(options)
28
+ elsif Symbology::EAN_13.include? symbology
29
+ return Symbology::Ean13.new(options)
30
+ elsif Symbology::MSI.include? symbology
31
+ return Symbology::Msi.new(options)
32
+ elsif Symbology::MSI_MOD_10.include? symbology
33
+ return Symbology::MsiMod10.new(options)
34
+ elsif Symbology::MSI_MOD_11.include? symbology
35
+ return Symbology::MsiMod11.new(options)
36
+ elsif Symbology::STANDARD_2_OF_5.include? symbology
37
+ return Symbology::Standard2Of5.new(options)
38
+ elsif Symbology::STANDARD_2_OF_5_MOD_10.include? symbology
39
+ return Symbology::Standard2Of5Mod10.new(options)
40
+ elsif Symbology::INTERLEAVED_2_OF_5.include? symbology
41
+ return Symbology::Interleaved2Of5.new(options)
42
+ elsif Symbology::INTERLEAVED_2_OF_5_MOD_10.include? symbology
43
+ return Symbology::Interleaved2Of5Mod10.new(options)
44
+ elsif Symbology::PLANET.include? symbology
45
+ return Symbology::Planet.new(options)
46
+ elsif Symbology::POSTNET.include? symbology
47
+ return Symbology::Postnet.new(options)
48
+ elsif Symbology::UPC_A.include? symbology
49
+ return Symbology::UpcA.new(options)
50
+ else
51
+ raise ArgumentError, 'Unsupported symbology'
52
+ end
53
+ end
54
+
55
+ def render(symbology, filename=nil, options={}, renderer=Barcodes::Renderer::PDF)
56
+ if renderer == Barcodes::Renderer::ASCII
57
+ Barcodes::Renderer::Ascii.new(self.create(symbology, options)).render(filename)
58
+ elsif renderer == Barcodes::Renderer::PDF
59
+ Barcodes::Renderer::Pdf.new(self.create(symbology, options)).render(filename)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,74 @@
1
+ require 'optparse'
2
+
3
+ require 'barcodes'
4
+ require 'barcodes/version'
5
+
6
+ module Barcodes
7
+ class Exec
8
+ attr_reader :argv
9
+ attr_reader :parser
10
+ attr_reader :options
11
+ attr_reader :command
12
+ attr_reader :arguments
13
+
14
+ def initialize(argv)
15
+ @argv = argv
16
+ @options = {}
17
+ self._init_parser
18
+ end
19
+
20
+ def run
21
+ self._parse!
22
+
23
+ unless @symbology.nil?
24
+ unless @options[:ascii]
25
+ Barcodes.render(@symbology, @target, @options)
26
+ else
27
+ Barcodes.render(@symbology, @target, @options, Barcodes::Renderer::Ascii)
28
+ end
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ def _init_parser
35
+ @parser ||= OptionParser.new do |opts|
36
+ opts.banner = "Usage: barcodes [OPTIONS] symbology target"
37
+ opts.separator ""
38
+ opts.on('-D', '--data [DATA]', 'The barcode data to encode (0123456789)') { |v| options[:data] = v ||= '0123456789' }
39
+ opts.on('-s', '--start_character [START_CHARACTER]', 'The barcode start character if applicable') { |v| options[:start_character] = v ||= '' }
40
+ opts.on('-e', '--stop_character [STOP_CHARACTER]', 'The barcode stop character if applicable') { |v| options[:stop_character] = v ||= '' }
41
+ opts.on('-W', '--bar_width [BAR_WIDTH]', 'The barcode bar width in mils (20)') { |v| options[:bar_width] = v.to_i ||= 20 }
42
+ opts.on('-H', '--bar_height [BAR_HEIGHT]', 'The barcode bar height in mils (1000)') { |v| options[:bar_height] = v.to_i ||= 1000 }
43
+ opts.on('-c', '--caption_height [CAPTION_HEIGHT]', 'The barcode caption height in mils (180)') { |v| options[:caption_height] = v.to_i ||= 180 }
44
+ opts.on('-p', '--caption_size [CAPTION_SIZE]', 'The caption font size in mils (167)') { |v| options[:font_size] = v.to_f ||= 167 }
45
+ opts.on('-A', '--alpha [ALPHA]', 'The barcode transparency (1.0)') { |v| options[:alpha] = v.to_f ||= 1.0 }
46
+ opts.on('-O', '--color [COLOR]', 'The barcode color in hex (000000)') { |v| options[:color] = v ||= '000000' }
47
+ opts.on('-a', '--captioned', 'Render barcode caption (true)') { |v| options[:captioned] = v ||= true }
48
+ opts.on('-i', '--ascii', 'Render barcode as ASCII string (false)') { |v| options[:ascii] = v ||= false }
49
+ opts.on('-v', '--version') { puts version; exit }
50
+ opts.on('-h', '--help') { puts opts; exit }
51
+ opts.separator ""
52
+ end
53
+ end
54
+
55
+ def _parse!
56
+
57
+ begin
58
+ @parser.parse!(@argv)
59
+ rescue
60
+ puts @parser.help
61
+ exit 1
62
+ end
63
+
64
+ @symbology = @argv.shift
65
+ @target = @argv.shift
66
+ @arguments = @argv
67
+
68
+ end
69
+
70
+ def _version
71
+ "barcodes #{Barcodes::VERSION}"
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,9 @@
1
+ require 'barcodes/renderer/ascii'
2
+ require 'barcodes/renderer/pdf'
3
+
4
+ module Barcodes
5
+ module Renderer
6
+ ASCII = 'ascii'
7
+ PDF = 'pdf'
8
+ end
9
+ end
@@ -0,0 +1,199 @@
1
+ module Barcodes
2
+ module Renderer
3
+ class Ascii
4
+ attr_accessor :barcode
5
+
6
+ def initialize(barcode=nil)
7
+ @barcode = barcode
8
+ end
9
+
10
+ def render(filename=nil)
11
+ rendering = ''
12
+ if @barcode.class == Barcodes::Symbology::Ean8
13
+ rendering = self._render_ean8(@barcode)
14
+ elsif @barcode.class == Barcodes::Symbology::Ean13
15
+ rendering = self._render_ean13(@barcode)
16
+ elsif @barcode.class == Barcodes::Symbology::Planet || @barcode.class == Barcodes::Symbology::Postnet
17
+ rendering = self._render_planet_postnet(@barcode)
18
+ elsif @barcode.class == Barcodes::Symbology::UpcA
19
+ rendering = self._render_upca(@barcode)
20
+ else
21
+ rendering = self._render_standard(@barcode)
22
+ end
23
+
24
+ unless filename.nil?
25
+ File.open(filename, 'w') {|f| f.write(rendering) }
26
+ else
27
+ rendering
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def _render_standard(barcode)
34
+ ascii = ""
35
+ 10.times do |i|
36
+ barcode.encoded_data.each_char do |char|
37
+ if char == '1'
38
+ ascii += "*"
39
+ else
40
+ ascii += " "
41
+ end
42
+ end
43
+ ascii += "\n"
44
+ end
45
+
46
+ if barcode.captioned
47
+ offset = ((barcode.encoded_data.length - barcode.caption_data.length) / 2).floor
48
+ offset.times do |t|
49
+ ascii += ' '
50
+ end
51
+ ascii += barcode.caption_data + "\n"
52
+ end
53
+ ascii += "\n"
54
+ end
55
+
56
+ def _render_ean8(barcode)
57
+ encoded_data = barcode.encoded_data
58
+
59
+ ascii = ""
60
+ 10.times do |i|
61
+ ascii += " "
62
+ encoded_data.each_char do |char|
63
+ if char == '1'
64
+ ascii += "*"
65
+ else
66
+ ascii += " "
67
+ end
68
+ end
69
+ ascii += " \n"
70
+ end
71
+
72
+ ascii += " "
73
+ encoded_data.length.times.each do |index|
74
+ if encoded_data[index] == '1' && ((index >= 0 && index <= 3) || (index >= 32 && index <= 35) || (index >= 65))
75
+ ascii += "*"
76
+ elsif (index >= 14 && index < 18)
77
+ if barcode.captioned
78
+ ascii += barcode.caption_data[index - 13]
79
+ end
80
+ elsif (index >= 49 && index < 53)
81
+ if barcode.captioned
82
+ ascii += barcode.caption_data[index - 45]
83
+ end
84
+ else
85
+ ascii += " "
86
+ end
87
+ end
88
+ ascii += " \n"
89
+ end
90
+
91
+ def _render_ean13(barcode)
92
+ encoded_data = barcode.encoded_data
93
+
94
+ ascii = ""
95
+ 10.times do |i|
96
+ if i == 9
97
+ if barcode.captioned
98
+ ascii += barcode.caption_data[0] + " "
99
+ end
100
+ else
101
+ ascii += " "
102
+ end
103
+ encoded_data.each_char do |char|
104
+ if char == '1'
105
+ ascii += "*"
106
+ else
107
+ ascii += " "
108
+ end
109
+ end
110
+ ascii += " \n"
111
+ end
112
+
113
+ ascii += " "
114
+ encoded_data.length.times.each do |index|
115
+ if encoded_data[index] == '1' && ((index >= 0 && index <= 3) || (index >= 46 && index <= 49) || (index >= 93))
116
+ ascii += "*"
117
+ elsif (index >= 21 && index < 27)
118
+ if barcode.captioned
119
+ ascii += barcode.caption_data[index - 21]
120
+ end
121
+ elsif (index >= 69 && index < 75)
122
+ if barcode.captioned
123
+ ascii += barcode.caption_data[index - 63]
124
+ end
125
+ else
126
+ ascii += " "
127
+ end
128
+ end
129
+ ascii += " \n"
130
+ end
131
+
132
+ def _render_planet_postnet(barcode)
133
+ ascii = ""
134
+ 6.times do |i|
135
+ barcode.encoded_data.each_char do |char|
136
+ if char == '1'
137
+ ascii += "* "
138
+ else
139
+ if i < 3
140
+ ascii += " "
141
+ else
142
+ ascii += "* "
143
+ end
144
+ end
145
+ end
146
+ ascii += "\n"
147
+ end
148
+ ascii += "\n"
149
+ end
150
+
151
+ def _render_upca(barcode)
152
+ encoded_data = barcode.encoded_data
153
+
154
+ ascii = ""
155
+ 10.times do |i|
156
+ if i == 9
157
+ if barcode.captioned
158
+ ascii += barcode.caption_data[0] + " "
159
+ end
160
+ else
161
+ ascii += " "
162
+ end
163
+ encoded_data.each_char do |char|
164
+ if char == '1'
165
+ ascii += "*"
166
+ else
167
+ ascii += " "
168
+ end
169
+ end
170
+ if i == 9
171
+ if barcode.captioned
172
+ ascii += " " + barcode.caption_data[barcode.caption_data.length - 1] + "\n"
173
+ end
174
+ else
175
+ ascii += " \n"
176
+ end
177
+ end
178
+
179
+ ascii += " "
180
+ encoded_data.length.times.each do |index|
181
+ if encoded_data[index] == '1' && ((index >= 0 && index <= 3) || (index >= 46 && index <= 49) || (index >= 93))
182
+ ascii += "*"
183
+ elsif (index >= 22 && index < 27)
184
+ if barcode.captioned
185
+ ascii += barcode.caption_data[index - 21]
186
+ end
187
+ elsif (index >= 70 && index < 75)
188
+ if barcode.captioned
189
+ ascii += barcode.caption_data[index - 63]
190
+ end
191
+ else
192
+ ascii += " "
193
+ end
194
+ end
195
+ ascii += " \n"
196
+ end
197
+ end
198
+ end
199
+ end