Class: Barcodes::Symbology::Code39Extended
- Defined in:
- lib/barcodes/symbology/code39extended.rb
Overview
This class represents the Code 39 Extended symbology. Code 39 Extended can encode all standard ASCII characters.
More info: en.wikipedia.org/wiki/Code_39
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#alpha, #bar_height, #bar_width, #caption_height, #caption_size, #captioned, #color, #data
Instance Method Summary collapse
-
#_data ⇒ Object
Returns prepared barcode data by replacing extended characters.
-
#formatted_data ⇒ Object
Start character + prepared data + stop character.
-
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid.
Methods inherited from Code39
#caption_data, charset, #initialize, valueset
Methods inherited from Base
#caption_data, charset, #encoded_data, #height, #initialize, #quiet_zone_width, valueset, #width
Constructor Details
This class inherits a constructor from Barcodes::Symbology::Code39
Instance Method Details
#_data ⇒ Object
Returns prepared barcode data by replacing extended characters
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/barcodes/symbology/code39extended.rb', line 40 def _data prepared_data = "" self.data.each_byte do |character| case character when 0 prepared_data += '%' + 'U' when 1..26 prepared_data += '$' + (character + 64).chr when 27..31 prepared_data += '%' + (character + 38).chr when 127 prepared_data += '%' + 'T' when '!'.bytes.to_a[0] prepared_data += '/' + 'A' when '"'.bytes.to_a[0] prepared_data += '/' + 'B' when '#'.bytes.to_a[0] prepared_data += '/' + 'C' when '$'.bytes.to_a[0] prepared_data += '/' + 'D' when '%'.bytes.to_a[0] prepared_data += '/' + 'E' when '&'.bytes.to_a[0] prepared_data += '/' + 'F' when '\''.bytes.to_a[0] prepared_data += '/' + 'G' when '('.bytes.to_a[0] prepared_data += '/' + 'H' when ')'.bytes.to_a[0] prepared_data += '/' + 'I' when '*'.bytes.to_a[0] prepared_data += '/' + 'J' when '+'.bytes.to_a[0] prepared_data += '/' + 'K' when ','.bytes.to_a[0] prepared_data += '/' + 'L' when '/'.bytes.to_a[0] prepared_data += '/' + 'O' when ':'.bytes.to_a[0] prepared_data += '/' + 'Z' when ';'.bytes.to_a[0] prepared_data += '%' + 'F' when '<'.bytes.to_a[0] prepared_data += '%' + 'G' when '='.bytes.to_a[0] prepared_data += '%' + 'H' when '>'.bytes.to_a[0] prepared_data += '%' + 'I' when '?'.bytes.to_a[0] prepared_data += '%' + 'J' when '@'.bytes.to_a[0] prepared_data += '%' + 'V' when '['.bytes.to_a[0] prepared_data += '%' + 'K' when '\\'.bytes.to_a[0] prepared_data += '%' + 'L' when ']'.bytes.to_a[0] prepared_data += '%' + 'M' when '^'.bytes.to_a[0] prepared_data += '%' + 'N' when '_'.bytes.to_a[0] prepared_data += '%' + '0' when '`'.bytes.to_a[0] prepared_data += '%' + 'W' when 97..122 prepared_data += '+' + character.chr.upcase when '{'.bytes.to_a[0] prepared_data += '%' + 'P' when '|'.bytes.to_a[0] prepared_data += '%' + 'Q' when '}'.bytes.to_a[0] prepared_data += '%' + 'R' when '~'.bytes.to_a[0] prepared_data += '%' + 'S' else prepared_data += character.chr end end return prepared_data end |
#formatted_data ⇒ Object
Start character + prepared data + stop character
19 20 21 |
# File 'lib/barcodes/symbology/code39extended.rb', line 19 def formatted_data @start_character + self._data + @stop_character end |
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/barcodes/symbology/code39extended.rb', line 25 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 |