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.
- data/Gemfile +6 -0
- data/README.md +24 -24
- data/Rakefile +6 -0
- data/barcodes.gemspec +6 -0
- data/lib/barcodes.rb +52 -0
- data/lib/barcodes/exec.rb +52 -31
- data/lib/barcodes/renderer.rb +6 -0
- data/lib/barcodes/renderer/ascii.rb +7 -0
- data/lib/barcodes/renderer/pdf.rb +6 -0
- data/lib/barcodes/symbology.rb +6 -0
- data/lib/barcodes/symbology/base.rb +55 -15
- data/lib/barcodes/symbology/codabar.rb +23 -0
- data/lib/barcodes/symbology/code11.rb +18 -0
- data/lib/barcodes/symbology/code128.rb +44 -5
- data/lib/barcodes/symbology/code39.rb +21 -0
- data/lib/barcodes/symbology/code39extended.rb +12 -0
- data/lib/barcodes/symbology/code39extendedmod43.rb +14 -0
- data/lib/barcodes/symbology/code39mod43.rb +14 -0
- data/lib/barcodes/symbology/code93.rb +23 -0
- data/lib/barcodes/symbology/code93extended.rb +17 -1
- data/lib/barcodes/symbology/ean.rb +28 -1
- data/lib/barcodes/symbology/ean13.rb +17 -0
- data/lib/barcodes/symbology/ean8.rb +18 -0
- data/lib/barcodes/symbology/interleaved2of5.rb +18 -0
- data/lib/barcodes/symbology/interleaved2of5mod10.rb +14 -0
- data/lib/barcodes/symbology/msi.rb +16 -0
- data/lib/barcodes/symbology/msimod10.rb +14 -0
- data/lib/barcodes/symbology/msimod11.rb +14 -0
- data/lib/barcodes/symbology/planet.rb +24 -1
- data/lib/barcodes/symbology/postnet.rb +24 -1
- data/lib/barcodes/symbology/standard2of5.rb +16 -0
- data/lib/barcodes/symbology/standard2of5mod10.rb +14 -0
- data/lib/barcodes/symbology/upca.rb +16 -0
- data/lib/barcodes/version.rb +9 -1
- data/spec/barcodes/exec_spec.rb +7 -1
- data/spec/barcodes/renderer/ascii_spec.rb +6 -0
- data/spec/barcodes/renderer/pdf_spec.rb +6 -0
- data/spec/barcodes/symbology/base_spec.rb +6 -0
- data/spec/barcodes/symbology/codabar_spec.rb +6 -0
- data/spec/barcodes/symbology/code11_spec.rb +6 -0
- data/spec/barcodes/symbology/code128_spec.rb +6 -0
- data/spec/barcodes/symbology/code39_spec.rb +6 -0
- data/spec/barcodes/symbology/code39extended_spec.rb +6 -0
- data/spec/barcodes/symbology/code39extendedmod43_spec.rb +6 -0
- data/spec/barcodes/symbology/code39mod43_spec.rb +6 -0
- data/spec/barcodes/symbology/code93_spec.rb +6 -0
- data/spec/barcodes/symbology/code93extended_spec.rb +6 -0
- data/spec/barcodes/symbology/ean13_spec.rb +6 -0
- data/spec/barcodes/symbology/ean8_spec.rb +6 -0
- data/spec/barcodes/symbology/ean_spec.rb +6 -0
- data/spec/barcodes/symbology/interleaved2of5_spec.rb +6 -0
- data/spec/barcodes/symbology/interleaved2of5mod10_spec.rb +6 -0
- data/spec/barcodes/symbology/msi_spec.rb +6 -0
- data/spec/barcodes/symbology/msimod10_spec.rb +6 -0
- data/spec/barcodes/symbology/msimod11_spec.rb +6 -0
- data/spec/barcodes/symbology/planet_spec.rb +6 -0
- data/spec/barcodes/symbology/postnet_spec.rb +6 -0
- data/spec/barcodes/symbology/standard2of5_spec.rb +6 -0
- data/spec/barcodes/symbology/standard2of5mod10_spec.rb +6 -0
- data/spec/barcodes/symbology/upca_spec.rb +6 -0
- data/spec/barcodes_spec.rb +6 -0
- data/spec/spec_helper.rb +6 -0
- metadata +8 -8
data/Gemfile
CHANGED
@@ -1,3 +1,9 @@
|
|
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
|
source "http://rubygems.org"
|
2
8
|
|
3
9
|
# Specify your gem's dependencies in labels.gemspec
|
data/README.md
CHANGED
@@ -35,53 +35,53 @@ Installation
|
|
35
35
|
|
36
36
|
Barcodes is a RubyGem and can be installed using:
|
37
37
|
|
38
|
-
|
38
|
+
$ gem install barcodes
|
39
39
|
|
40
40
|
Usage
|
41
41
|
-----
|
42
42
|
|
43
43
|
If you want to create and render a barcode all in one step you can simply do the following:
|
44
44
|
|
45
|
-
|
45
|
+
Barcodes.render('Codabar', '/path/to/output.pdf', {:data => '12345'})
|
46
46
|
|
47
47
|
The output path can be left empty and the rendered output will be returned as a string.
|
48
48
|
|
49
49
|
By default Barcodes uses the PDF renderer. To use the ASCII renderer you would do the following:
|
50
50
|
|
51
|
-
|
51
|
+
Barcodes.render('Codabar', '/path/to/output.pdf', {:data => '12345'}, Barcodes::Renderer::Ascii)
|
52
52
|
|
53
53
|
You could also do this:
|
54
54
|
|
55
|
-
|
55
|
+
barcode = Barcodes.create('Postnet', {:data => '44555'})
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
pdf_renderer = Barcodes::Renderer::Pdf.new(barcode)
|
58
|
+
pdf_renderer.render('/path/to/output.pdf')
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
ascii_renderer = Barcodes::Renderer::Ascii.new(barcode)
|
61
|
+
ascii_renderer.render('/path/to/output.txt')
|
62
62
|
|
63
|
-
The following options (defaults shown below) are available for all barcode symbologies:
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
63
|
+
The following options (defaults shown below) are available (where applicable) 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
77
|
|
78
78
|
Command Line
|
79
79
|
------------
|
80
80
|
|
81
81
|
Barcodes also provides a command line tool for rendering barcodes:
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
$ barcodes -h
|
84
|
+
Usage: barcodes [OPTIONS] symbology target
|
85
85
|
|
86
86
|
-D, --data [DATA] The barcode data to encode (0123456789)
|
87
87
|
-s [START_CHARACTER], The barcode start character if applicable
|
data/Rakefile
CHANGED
@@ -1,3 +1,9 @@
|
|
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 'bundler/gem_tasks'
|
2
8
|
|
3
9
|
require 'rspec/core/rake_task'
|
data/barcodes.gemspec
CHANGED
@@ -1,3 +1,9 @@
|
|
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
|
# -*- encoding: utf-8 -*-
|
2
8
|
$:.push File.expand_path("../lib", __FILE__)
|
3
9
|
require "barcodes/version"
|
data/lib/barcodes.rb
CHANGED
@@ -1,9 +1,53 @@
|
|
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/version'
|
2
8
|
require 'barcodes/symbology'
|
3
9
|
require 'barcodes/renderer'
|
4
10
|
|
11
|
+
# Barcodes is a RubyGem for creating and rendering common barcode symbologies. Here are some of the current features:
|
12
|
+
#
|
13
|
+
# * Many common symbologies to choose from
|
14
|
+
# * PDF and ASCII rendering support
|
15
|
+
# * Command line interface for rendering barcodes to console or file
|
16
|
+
#
|
17
|
+
# Currently supported symbologies:
|
18
|
+
#
|
19
|
+
# * Code 11
|
20
|
+
# * Code 128
|
21
|
+
# * Code 39
|
22
|
+
# * Code 39 Mod 43
|
23
|
+
# * Code 39 Extended
|
24
|
+
# * Code 39 Extended Mod 43
|
25
|
+
# * Code 93
|
26
|
+
# * Code 93 Extended
|
27
|
+
# * EAN8
|
28
|
+
# * EAN13
|
29
|
+
# * Interleaved 2 of 5
|
30
|
+
# * Interleaved 2 of 5 Mod 10
|
31
|
+
# * MSI
|
32
|
+
# * MSI Mod 10
|
33
|
+
# * MSI Mod 11
|
34
|
+
# * PLANET
|
35
|
+
# * POSTNET
|
36
|
+
# * Standard 2 of 5
|
37
|
+
# * Standard 2 of 5 Mod 10
|
38
|
+
# * UPC-A
|
39
|
+
|
5
40
|
module Barcodes
|
41
|
+
|
42
|
+
# This class is a helper for quickly instantiating
|
43
|
+
# a concrete barcode class and also provides a helper
|
44
|
+
# for quick rendering.
|
6
45
|
class << self
|
46
|
+
|
47
|
+
# Creates a new barcode of type <symbology> with given
|
48
|
+
# options and returns an instantiated instance.
|
49
|
+
#
|
50
|
+
# See Barcodes::Symbology::Base for options
|
7
51
|
def create(symbology, options={})
|
8
52
|
if Symbology::CODABAR.include? symbology
|
9
53
|
return Symbology::Codabar.new(options)
|
@@ -52,6 +96,14 @@ module Barcodes
|
|
52
96
|
end
|
53
97
|
end
|
54
98
|
|
99
|
+
# Creates a new barcode of type <symbology> with given
|
100
|
+
# options and renders barcode using given renderer.
|
101
|
+
#
|
102
|
+
# Optionally takes <filename> and <renderer>. If no
|
103
|
+
# filename is given rendering will be outputted as a
|
104
|
+
# string. Uses PDF renderer by default.
|
105
|
+
#
|
106
|
+
# See Barcodes::Symbology::Base for options
|
55
107
|
def render(symbology, filename=nil, options={}, renderer=Barcodes::Renderer::PDF)
|
56
108
|
if renderer == Barcodes::Renderer::ASCII
|
57
109
|
Barcodes::Renderer::Ascii.new(self.create(symbology, options)).render(filename)
|
data/lib/barcodes/exec.rb
CHANGED
@@ -1,72 +1,93 @@
|
|
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 'optparse'
|
2
8
|
|
3
9
|
require 'barcodes'
|
4
10
|
require 'barcodes/version'
|
5
11
|
|
6
12
|
module Barcodes
|
13
|
+
|
14
|
+
# This class is the main handler for the command line tool interface.
|
15
|
+
# It takes command line arguments and options and renders a barcode
|
16
|
+
# using those options.
|
7
17
|
class Exec
|
8
|
-
|
18
|
+
# The parser instance
|
9
19
|
attr_reader :parser
|
20
|
+
|
21
|
+
# Hash of parsed options
|
10
22
|
attr_reader :options
|
11
|
-
|
23
|
+
|
24
|
+
# The barcode symbology
|
25
|
+
attr_reader :symbology
|
26
|
+
|
27
|
+
# The output target
|
28
|
+
attr_reader :target
|
29
|
+
|
30
|
+
# Array of command line arguments
|
12
31
|
attr_reader :arguments
|
13
|
-
|
32
|
+
|
33
|
+
# Creates a new instance with given command line arguments and options
|
14
34
|
def initialize(argv)
|
15
|
-
@
|
35
|
+
@arguments = arguments
|
16
36
|
@options = {}
|
17
37
|
self._init_parser
|
38
|
+
self._parse!
|
18
39
|
end
|
19
|
-
|
40
|
+
|
41
|
+
# Runs the command and renders barcode
|
20
42
|
def run
|
21
|
-
self.
|
22
|
-
|
23
|
-
|
24
|
-
unless @options[:ascii]
|
25
|
-
Barcodes.render(@symbology, @target, @options)
|
43
|
+
unless self.symbology.nil?
|
44
|
+
unless self.options[:ascii]
|
45
|
+
Barcodes.render(self.symbology, self.target, self.options)
|
26
46
|
else
|
27
|
-
Barcodes.render(
|
47
|
+
Barcodes.render(self.symbology, self.target, self.options, Barcodes::Renderer::Ascii)
|
28
48
|
end
|
29
49
|
end
|
30
50
|
end
|
31
51
|
|
32
52
|
protected
|
33
|
-
|
53
|
+
|
54
|
+
# Initializes the option parser instance
|
34
55
|
def _init_parser
|
35
56
|
@parser ||= OptionParser.new do |opts|
|
36
57
|
opts.banner = "Usage: barcodes [OPTIONS] symbology target"
|
37
58
|
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
|
59
|
+
opts.on('-D', '--data [DATA]', 'The barcode data to encode (0123456789)') { |v| @options[:data] = v ||= '0123456789' }
|
60
|
+
opts.on('-s', '--start_character [START_CHARACTER]', 'The barcode start character if applicable') { |v| @options[:start_character] = v ||= '' }
|
61
|
+
opts.on('-e', '--stop_character [STOP_CHARACTER]', 'The barcode stop character if applicable') { |v| @options[:stop_character] = v ||= '' }
|
62
|
+
opts.on('-W', '--bar_width [BAR_WIDTH]', 'The barcode bar width in mils (20)') { |v| @options[:bar_width] = v.to_i ||= 20 }
|
63
|
+
opts.on('-H', '--bar_height [BAR_HEIGHT]', 'The barcode bar height in mils (1000)') { |v| @options[:bar_height] = v.to_i ||= 1000 }
|
64
|
+
opts.on('-c', '--caption_height [CAPTION_HEIGHT]', 'The barcode caption height in mils (180)') { |v| @options[:caption_height] = v.to_i ||= 180 }
|
65
|
+
opts.on('-p', '--caption_size [CAPTION_SIZE]', 'The caption font size in mils (167)') { |v| @options[:font_size] = v.to_f ||= 167 }
|
66
|
+
opts.on('-A', '--alpha [ALPHA]', 'The barcode transparency (1.0)') { |v| @options[:alpha] = v.to_f ||= 1.0 }
|
67
|
+
opts.on('-O', '--color [COLOR]', 'The barcode color in hex (000000)') { |v| @options[:color] = v ||= '000000' }
|
68
|
+
opts.on('-a', '--captioned', 'Render barcode caption (true)') { |v| @options[:captioned] = v ||= true }
|
69
|
+
opts.on('-i', '--ascii', 'Render barcode as ASCII string (false)') { |v| @options[:ascii] = v ||= false }
|
70
|
+
opts.on('-v', '--version') { puts self._version; exit }
|
50
71
|
opts.on('-h', '--help') { puts opts; exit }
|
51
72
|
opts.separator ""
|
52
73
|
end
|
53
74
|
end
|
54
75
|
|
76
|
+
# Parses the command line arguments
|
55
77
|
def _parse!
|
56
78
|
|
57
79
|
begin
|
58
|
-
|
80
|
+
self.parser.parse!(self.arguments)
|
59
81
|
rescue
|
60
|
-
puts
|
82
|
+
puts self.parser.help
|
61
83
|
exit 1
|
62
84
|
end
|
63
85
|
|
64
|
-
@symbology =
|
65
|
-
@target =
|
66
|
-
@arguments = @argv
|
67
|
-
|
86
|
+
@symbology = self.arguments.shift
|
87
|
+
@target = self.arguments.shift
|
68
88
|
end
|
69
|
-
|
89
|
+
|
90
|
+
# Returns the current version
|
70
91
|
def _version
|
71
92
|
"barcodes #{Barcodes::VERSION}"
|
72
93
|
end
|
data/lib/barcodes/renderer.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
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/renderer/ascii'
|
2
8
|
require 'barcodes/renderer/pdf'
|
3
9
|
|
@@ -1,3 +1,10 @@
|
|
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
|
+
|
7
|
+
#
|
1
8
|
module Barcodes
|
2
9
|
module Renderer
|
3
10
|
class Ascii
|
data/lib/barcodes/symbology.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
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/codabar'
|
2
8
|
require 'barcodes/symbology/code11'
|
3
9
|
require 'barcodes/symbology/code39'
|
@@ -1,31 +1,58 @@
|
|
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
|
+
|
7
|
+
#
|
1
8
|
module Barcodes
|
2
9
|
module Symbology
|
10
|
+
|
11
|
+
# Base class for all barcode symbologies.
|
3
12
|
class Base
|
13
|
+
# Data to be encoded.
|
4
14
|
attr_accessor :data
|
5
|
-
|
6
|
-
|
15
|
+
|
16
|
+
# Bar width in mils
|
7
17
|
attr_accessor :bar_width
|
18
|
+
|
19
|
+
# Bar height in mils
|
8
20
|
attr_accessor :bar_height
|
21
|
+
|
22
|
+
# Alpha (transparency)
|
9
23
|
attr_accessor :alpha
|
24
|
+
|
25
|
+
# Color in hex
|
10
26
|
attr_accessor :color
|
27
|
+
|
28
|
+
# Caption height in mils
|
11
29
|
attr_accessor :caption_height
|
30
|
+
|
31
|
+
# Caption font size in mils
|
12
32
|
attr_accessor :caption_size
|
33
|
+
|
34
|
+
# Whether or not to print caption
|
13
35
|
attr_accessor :captioned
|
14
36
|
|
37
|
+
# Returns the barcode symbologies character set as array of
|
38
|
+
# ASCII integer values. This method should be overridden by
|
39
|
+
# concrete subclass to provide character set for symbology.
|
15
40
|
def self.charset
|
16
41
|
# Should be overridden by subclass to provide charset
|
17
42
|
[].collect {|c| c.bytes.to_a[0] }
|
18
43
|
end
|
19
44
|
|
45
|
+
# Returns the values of the symbologies character set as
|
46
|
+
# array of encoded sets. This method should be overridden by
|
47
|
+
# concrete subclass to provide value set for symbology.
|
20
48
|
def self.valueset
|
21
|
-
# Should be overridden by subclass to provide valueset
|
22
49
|
[]
|
23
50
|
end
|
24
51
|
|
52
|
+
# Creates a new barcode instance with given arguments.
|
53
|
+
# See class attributes for list of acceptable arguments.
|
25
54
|
def initialize(args={})
|
26
55
|
@data = '0123456789'
|
27
|
-
@start_character = ''
|
28
|
-
@stop_character = ''
|
29
56
|
@bar_width = 20
|
30
57
|
@bar_height = 1000
|
31
58
|
@alpha = 1.0
|
@@ -38,17 +65,22 @@ module Barcodes
|
|
38
65
|
instance_variable_set("@#{k}", v) unless v.nil?
|
39
66
|
end
|
40
67
|
end
|
41
|
-
|
68
|
+
|
69
|
+
# Returns the data to be printed in barcode caption.
|
70
|
+
# Could be overridden by concrete subclass to provide
|
71
|
+
# additional formatting.
|
42
72
|
def caption_data
|
43
|
-
# Can be overridden by subclass to format data string for display
|
44
73
|
self.data
|
45
74
|
end
|
46
|
-
|
75
|
+
|
76
|
+
# Returns the formatted barcode data to be encoded
|
77
|
+
# Could be overridden by concrete subclass to add additional
|
78
|
+
# formatting to data string.
|
47
79
|
def formatted_data
|
48
|
-
# Can be overridden by subclass to add additional formatting to data string
|
49
80
|
self.data
|
50
81
|
end
|
51
82
|
|
83
|
+
# Returns the formatted barcode data encoded as 1's and 0's.
|
52
84
|
def encoded_data
|
53
85
|
if self.valid?
|
54
86
|
encoded_data = ""
|
@@ -59,11 +91,14 @@ module Barcodes
|
|
59
91
|
end
|
60
92
|
end
|
61
93
|
|
94
|
+
# Returns the symbologies quiet zone width in mils.
|
95
|
+
# Should be overridden by concrete subclass to provide
|
96
|
+
# quiet zone width if applicable.
|
62
97
|
def quiet_zone_width
|
63
|
-
# Can be overriden in subclass to adjust quiet zone width
|
64
98
|
0
|
65
99
|
end
|
66
|
-
|
100
|
+
|
101
|
+
# Returns the overall width of the barcode in mils.
|
67
102
|
def width
|
68
103
|
if valid?
|
69
104
|
(self.encoded_data.length * self.bar_width) + (self.quiet_zone_width * 2)
|
@@ -71,13 +106,16 @@ module Barcodes
|
|
71
106
|
0
|
72
107
|
end
|
73
108
|
end
|
74
|
-
|
109
|
+
|
110
|
+
# Returns the overall height of the barcode in mils.
|
75
111
|
def height
|
76
112
|
self.captioned ? self.caption_height + self.bar_height : self.bar_height
|
77
113
|
end
|
78
|
-
|
114
|
+
|
115
|
+
# Determines whether or not the barcode data to be encoded
|
116
|
+
# is valid.
|
117
|
+
# Should be overridden in concrete subclass to provide validation.
|
79
118
|
def valid?
|
80
|
-
# Can be overridden in subclass to validate barcode
|
81
119
|
valid = self.data.length > 0 ? true : false
|
82
120
|
|
83
121
|
self.data.each_byte do |char|
|
@@ -90,7 +128,9 @@ module Barcodes
|
|
90
128
|
end
|
91
129
|
|
92
130
|
protected
|
93
|
-
|
131
|
+
|
132
|
+
# Encodes a single given ASCII character (as integer) into 1's and 0's.
|
133
|
+
# Returns nil if character is not found in character set.
|
94
134
|
def _encode_character(character)
|
95
135
|
if self.class.charset.include? character
|
96
136
|
return self.class.valueset.at(self.class.charset.index(character))
|