Class: Barcodes::Symbology::Base
- Inherits:
-
Object
- Object
- Barcodes::Symbology::Base
- Defined in:
- lib/barcodes/symbology/base.rb
Overview
Base class for all barcode symbologies.
Direct Known Subclasses
Codabar, Code11, Code128, Code39, Code93, Ean, Interleaved2Of5, Msi, Planet, Postnet, Standard2Of5
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Alpha (transparency).
-
#bar_height ⇒ Object
Bar height in mils.
-
#bar_width ⇒ Object
Bar width in mils.
-
#caption_height ⇒ Object
Caption height in mils.
-
#caption_size ⇒ Object
Caption font size in mils.
-
#captioned ⇒ Object
Whether or not to print caption.
-
#color ⇒ Object
Color in hex.
-
#data ⇒ Object
Data to be encoded.
Class Method Summary collapse
-
.charset ⇒ Object
Returns the barcode symbologies character set as array of ASCII integer values.
-
.valueset ⇒ Object
Returns the values of the symbologies character set as array of encoded sets.
Instance Method Summary collapse
-
#caption_data ⇒ Object
Returns the data to be printed in barcode caption.
-
#encoded_data ⇒ Object
Returns the formatted barcode data encoded as 1’s and 0’s.
-
#formatted_data ⇒ Object
Returns the formatted barcode data to be encoded Could be overridden by concrete subclass to add additional formatting to data string.
-
#height ⇒ Object
Returns the overall height of the barcode in mils.
-
#initialize(args = {}) ⇒ Base
constructor
Creates a new barcode instance with given arguments.
-
#quiet_zone_width ⇒ Object
Returns the symbologies quiet zone width in mils.
-
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid.
-
#width ⇒ Object
Returns the overall width of the barcode in mils.
Constructor Details
#initialize(args = {}) ⇒ Base
Creates a new barcode instance with given arguments. See class attributes for list of acceptable arguments.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/barcodes/symbology/base.rb', line 54 def initialize(args={}) @data = '0123456789' @bar_width = 20 @bar_height = 1000 @alpha = 1.0 @color = '000000' @caption_height = 180 @caption_size = 167 @captioned = true args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#alpha ⇒ Object
Alpha (transparency)
23 24 25 |
# File 'lib/barcodes/symbology/base.rb', line 23 def alpha @alpha end |
#bar_height ⇒ Object
Bar height in mils
20 21 22 |
# File 'lib/barcodes/symbology/base.rb', line 20 def @bar_height end |
#bar_width ⇒ Object
Bar width in mils
17 18 19 |
# File 'lib/barcodes/symbology/base.rb', line 17 def @bar_width end |
#caption_height ⇒ Object
Caption height in mils
29 30 31 |
# File 'lib/barcodes/symbology/base.rb', line 29 def caption_height @caption_height end |
#caption_size ⇒ Object
Caption font size in mils
32 33 34 |
# File 'lib/barcodes/symbology/base.rb', line 32 def caption_size @caption_size end |
#captioned ⇒ Object
Whether or not to print caption
35 36 37 |
# File 'lib/barcodes/symbology/base.rb', line 35 def captioned @captioned end |
#color ⇒ Object
Color in hex
26 27 28 |
# File 'lib/barcodes/symbology/base.rb', line 26 def color @color end |
#data ⇒ Object
Data to be encoded.
14 15 16 |
# File 'lib/barcodes/symbology/base.rb', line 14 def data @data end |
Class Method Details
.charset ⇒ Object
Returns the barcode symbologies character set as array of ASCII integer values. This method should be overridden by concrete subclass to provide character set for symbology.
40 41 42 43 |
# File 'lib/barcodes/symbology/base.rb', line 40 def self.charset # Should be overridden by subclass to provide charset [].collect {|c| c.bytes.to_a[0] } end |
.valueset ⇒ Object
Returns the values of the symbologies character set as array of encoded sets. This method should be overridden by concrete subclass to provide value set for symbology.
48 49 50 |
# File 'lib/barcodes/symbology/base.rb', line 48 def self.valueset [] end |
Instance Method Details
#caption_data ⇒ Object
Returns the data to be printed in barcode caption. Could be overridden by concrete subclass to provide additional formatting.
72 73 74 |
# File 'lib/barcodes/symbology/base.rb', line 72 def caption_data self.data end |
#encoded_data ⇒ Object
Returns the formatted barcode data encoded as 1’s and 0’s.
84 85 86 87 88 89 90 91 92 |
# File 'lib/barcodes/symbology/base.rb', line 84 def encoded_data if self.valid? encoded_data = "" self.formatted_data.each_byte do |char| encoded_data += self._encode_character char end encoded_data end end |
#formatted_data ⇒ Object
Returns the formatted barcode data to be encoded Could be overridden by concrete subclass to add additional formatting to data string.
79 80 81 |
# File 'lib/barcodes/symbology/base.rb', line 79 def formatted_data self.data end |
#height ⇒ Object
Returns the overall height of the barcode in mils.
111 112 113 |
# File 'lib/barcodes/symbology/base.rb', line 111 def height self.captioned ? self.caption_height + self. : self. end |
#quiet_zone_width ⇒ Object
Returns the symbologies quiet zone width in mils. Should be overridden by concrete subclass to provide quiet zone width if applicable.
97 98 99 |
# File 'lib/barcodes/symbology/base.rb', line 97 def quiet_zone_width 0 end |
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid. Should be overridden in concrete subclass to provide validation.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/barcodes/symbology/base.rb', line 118 def valid? valid = self.data.length > 0 ? true : false self.data.each_byte do |char| if self._encode_character(char).nil? return false end end return valid end |
#width ⇒ Object
Returns the overall width of the barcode in mils.
102 103 104 105 106 107 108 |
# File 'lib/barcodes/symbology/base.rb', line 102 def width if valid? (self.encoded_data.length * self.) + (self.quiet_zone_width * 2) else 0 end end |