Class Barby::Code93
In: lib/barby/barcode/code_93.rb
Parent: Barcode1D
Barcode1D EAN13 Code128 Code25 Code93 Code39 Bookland EAN8 Barcode Barcode2D QrCode Code128A Code128B Code128C GS1128 Outputter CairoOutputter PngOutputter ASCIIOutputter RmagickOutputter PDFWriterOutputter SvgOutputter PrawnOutputter Code25IATA Code25Interleaved lib/barby/barcode/gs1_128.rb lib/barby/outputter/png_outputter.rb lib/barby/outputter/svg_outputter.rb lib/barby/outputter/rmagick_outputter.rb lib/barby/barcode.rb lib/barby/outputter/ascii_outputter.rb lib/barby/outputter.rb lib/barby/barcode/code_128.rb lib/barby/barcode/code_39.rb lib/barby/outputter/pdfwriter_outputter.rb lib/barby/barcode/code_93.rb lib/barby/outputter/prawn_outputter.rb lib/barby/barcode/ean_8.rb lib/barby/barcode/code_25_iata.rb lib/barby/outputter/cairo_outputter.rb lib/barby/barcode/ean_13.rb lib/barby/barcode/code_25.rb lib/barby/barcode/code_25_interleaved.rb lib/barby/barcode/qr_code.rb lib/barby/barcode/bookland.rb VERSION Barby dot/m_22_0.png

Methods

Constants

SHIFT_DOLLAR = "\301"
SHIFT_PERCENT = "\302"
SHIFT_SLASH = "\303"
SHIFT_PLUS = "\304"
SHIFT_CHARACTERS = [SHIFT_DOLLAR, SHIFT_PERCENT, SHIFT_SLASH, SHIFT_PLUS]
ENCODINGS = { "0" => "100010100", "1" => "101001000", "2" => "101000100", "3" => "101000010", "4" => "100101000", "5" => "100100100", "6" => "100100010", "7" => "101010000", "8" => "100010010", "9" => "100001010", "A" => "110101000", "B" => "110100100", "C" => "110100010", "D" => "110010100", "E" => "110010010", "F" => "110001010", "G" => "101101000", "H" => "101100100", "I" => "101100010", "J" => "100110100", "K" => "100011010", "L" => "101011000", "M" => "101001100", "N" => "101000110", "O" => "100101100", "P" => "100010110", "Q" => "110110100", "R" => "110110010", "S" => "110101100", "T" => "110100110", "U" => "110010110", "V" => "110011010", "W" => "101101100", "X" => "101100110", "Y" => "100110110", "Z" => "100111010", "-" => "100101110", "." => "111010100", " " => "111010010", "$" => "111001010", "/" => "101101110", "+" => "101110110", "%" => "110101110", SHIFT_DOLLAR => "100100110", SHIFT_PERCENT => "111011010", SHIFT_SLASH => "111010110", SHIFT_PLUS => "100110010"
EXTENDED_MAPPING = { "\000" => "\302U", " " => " ", "@" => "\302V", "`" => "\302W", "\001" => "\301A", "!" => "\303A", "A" => "A", "a" => "\304A", "\002" => "\301B", '"' => "\303B", "B" => "B", "b" => "\304B", "\003" => "\301C", "#" => "\303C", "C" => "C", "c" => "\304C", "\004" => "\301D", "$" => "\303D", "D" => "D", "d" => "\304D", "\005" => "\301E", "%" => "\303E", "E" => "E", "e" => "\304E", "\006" => "\301F", "&" => "\303F", "F" => "F", "f" => "\304F", "\007" => "\301G", "'" => "\303G", "G" => "G", "g" => "\304G", "\010" => "\301H", "(" => "\303H", "H" => "H", "h" => "\304H", "\011" => "\301I", ")" => "\303I", "I" => "I", "i" => "\304I", "\012" => "\301J", "*" => "\303J", "J" => "J", "j" => "\304J", "\013" => "\301K", "/" => "\303K", "K" => "K", "k" => "\304K", "\014" => "\301L", "," => "\303L", "L" => "L", "l" => "\304L", "\015" => "\301M", "-" => "-", "M" => "M", "m" => "\304M", "\016" => "\301N", "." => ".", "N" => "N", "n" => "\304N", "\017" => "\301O", "+" => "\303O", "O" => "O", "o" => "\304O", "\020" => "\301P", "0" => "0", "P" => "P", "p" => "\304P", "\021" => "\301Q", "1" => "1", "Q" => "Q", "q" => "\304Q", "\022" => "\301R", "2" => "2", "R" => "R", "r" => "\304R", "\023" => "\301S", "3" => "3", "S" => "S", "s" => "\304S", "\024" => "\301T", "4" => "4", "T" => "T", "t" => "\304T", "\025" => "\301U", "5" => "5", "U" => "U", "u" => "\304U", "\026" => "\301V", "6" => "6", "V" => "V", "v" => "\304V", "\027" => "\301W", "7" => "7", "W" => "W", "w" => "\304W", "\030" => "\301X", "8" => "8", "X" => "X", "x" => "\304X", "\031" => "\301Y", "9" => "9", "Y" => "Y", "y" => "\304Y", "\032" => "\301Z", ":" => "\303Z", "Z" => "Z", "z" => "\304Z", "\033" => "\302A", ";" => "\302F", "[" => "\302K", "{" => "\302P", "\034" => "\302B", "<" => "\302G", "\\" => "\302L", "|" => "\302Q", "\035" => "\302C", "=" => "\302H", "]" => "\302M", "}" => "\302R", "\036" => "\302D", ">" => "\302I", "^" => "\302N", "~" => "\302S", "\037" => "\302E", "?" => "\302J", "_" => "\302O", "\177" => "\302T"
EXTENDED_CHARACTERS = EXTENDED_MAPPING.keys - ENCODINGS.keys
CHARACTERS = { 0 => "0", 1 => "1", 2 => "2", 3 => "3", 4 => "4", 5 => "5", 6 => "6", 7 => "7", 8 => "8", 9 => "9", 10 => "A", 11 => "B", 12 => "C", 13 => "D", 14 => "E", 15 => "F", 16 => "G", 17 => "H", 18 => "I", 19 => "J", 20 => "K", 21 => "L", 22 => "M", 23 => "N", 24 => "O", 25 => "P", 26 => "Q", 27 => "R", 28 => "S", 29 => "T", 30 => "U", 31 => "V", 32 => "W", 33 => "X", 34 => "Y", 35 => "Z", 36 => "-", 37 => ".", 38 => " ", 39 => "$", 40 => "/", 41 => "+", 42 => "%", 43 => SHIFT_DOLLAR, 44 => SHIFT_PERCENT, 45 => SHIFT_SLASH, 46 => SHIFT_PLUS
VALUES = CHARACTERS.invert
START_ENCODING = '101011110'
STOP_ENCODING = '101011110'
TERMINATE_ENCODING = '1'

Attributes

data  [RW] 

Public Class methods

[Source]

     # File lib/barby/barcode/code_93.rb, line 105
105:     def initialize(data)
106:       self.data = data
107:     end

Public Instance methods

Calculates the C checksum based on checksum_values

[Source]

     # File lib/barby/barcode/code_93.rb, line 183
183:     def c_checksum
184:       sum = 0
185:       checksum_values.each_with_index do |value, index|
186:         sum += ((index % 20) + 1) * value
187:       end
188:       sum % 47
189:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 191
191:     def c_checksum_character
192:       CHARACTERS[c_checksum]
193:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 195
195:     def c_checksum_encoding
196:       ENCODINGS[c_checksum_character]
197:     end
character_encodings()

Alias for encoded_characters

[Source]

     # File lib/barby/barcode/code_93.rb, line 119
119:     def characters
120:       raw_characters.map{|c| EXTENDED_MAPPING[c].split(//) }.flatten
121:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 164
164:     def checksum_characters
165:       checksums.map{|s| CHARACTERS[s] }
166:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 155
155:     def checksum_encoding
156:       checksum_encodings.join
157:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 151
151:     def checksum_encodings
152:       checksum_characters.map{|c| ENCODINGS[c] }
153:     end

Returns the values used for computing the C checksum in the "right" order (i.e. reversed)

[Source]

     # File lib/barby/barcode/code_93.rb, line 171
171:     def checksum_values
172:       characters.map{|c| VALUES[c] }.reverse
173:     end

Returns the normal checksum plus the c_checksum This is used for calculating the k_checksum

[Source]

     # File lib/barby/barcode/code_93.rb, line 177
177:     def checksum_values_with_c_checksum
178:       [c_checksum] + checksum_values
179:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 160
160:     def checksums
161:       [c_checksum, k_checksum]
162:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 143
143:     def data_encoding
144:       character_encodings.join
145:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 147
147:     def data_encoding_with_checksums
148:       (character_encodings + checksum_encodings).join
149:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 123
123:     def encoded_characters
124:       characters.map{|c| ENCODINGS[c] }
125:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 139
139:     def encoding
140:       start_encoding+data_encoding_with_checksums+stop_encoding
141:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 110
110:     def extended?
111:       raw_characters.any?{|c| EXTENDED_CHARACTERS.include?(c) }
112:     end

Calculates the K checksum based on checksum_values_with_c_checksum

[Source]

     # File lib/barby/barcode/code_93.rb, line 201
201:     def k_checksum
202:       sum = 0
203:       checksum_values_with_c_checksum.each_with_index do |value, index|
204:         sum += ((index % 15) + 1) * value
205:       end
206:       sum % 47
207:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 209
209:     def k_checksum_character
210:       CHARACTERS[k_checksum]
211:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 213
213:     def k_checksum_encoding
214:       ENCODINGS[k_checksum_character]
215:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 115
115:     def raw_characters
116:       data.split(//)
117:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 129
129:     def start_encoding
130:       START_ENCODING
131:     end

The stop encoding includes the termination bar

[Source]

     # File lib/barby/barcode/code_93.rb, line 134
134:     def stop_encoding
135:       STOP_ENCODING+TERMINATE_ENCODING
136:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 223
223:     def to_s
224:       data
225:     end

[Source]

     # File lib/barby/barcode/code_93.rb, line 218
218:     def valid?
219:       characters.all?{|c| ENCODINGS.include?(c) }
220:     end

[Validate]