Class: Barcodes::Symbology::Code11
- Defined in:
- lib/barcodes/symbology/code11.rb
Overview
This class represents the Code 11 symbology. Code 11 can encode the numbers 0-9 and the ‘-’ dash symbol.
More info: en.wikipedia.org/wiki/Code_11
Instance Attribute Summary
Attributes inherited from Base
#alpha, #bar_height, #bar_width, #caption_height, #caption_size, #captioned, #color, #data
Class Method Summary collapse
-
.charset ⇒ Object
The Code 11 character set 0-9 and the ‘-’ dash symbol.
-
.valueset ⇒ Object
The Code 11 values set.
Instance Method Summary collapse
-
#checksum ⇒ Object
Calculates the C and K checksums from the barcode data.
-
#formatted_data ⇒ Object
Start character + data + checksum + stop character.
-
#initialize(args = {}) ⇒ Code11
constructor
Creates a new Code11 instance.
Methods inherited from Base
#caption_data, #encoded_data, #height, #quiet_zone_width, #valid?, #width
Constructor Details
#initialize(args = {}) ⇒ Code11
Creates a new Code11 instance.
34 35 36 37 38 39 |
# File 'lib/barcodes/symbology/code11.rb', line 34 def initialize(args={}) super(args) @start_character = 'S' @stop_character = 'S' end |
Class Method Details
.charset ⇒ Object
The Code 11 character set 0-9 and the ‘-’ dash symbol.
19 20 21 |
# File 'lib/barcodes/symbology/code11.rb', line 19 def self.charset ['0','1','2','3','4','5','6','7','8','9','-','S'].collect {|c| c.bytes.to_a[0] } end |
.valueset ⇒ Object
The Code 11 values set
24 25 26 27 28 29 30 31 |
# File 'lib/barcodes/symbology/code11.rb', line 24 def self.valueset [ '1010110','11010110','10010110', '11001010','10110110','11011010', '10011010','10100110','11010010', '1101010','1011010','10110010' ] end |
Instance Method Details
#checksum ⇒ Object
Calculates the C and K checksums from the barcode data
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/barcodes/symbology/code11.rb', line 50 def checksum if valid? unless @data.length >= 10 c_value = self._checksum(@data, 10) return c_value else c_value = self._checksum(@data, 10) k_value = self._checksum(@data + c_value, 9) return c_value + k_value end end end |
#formatted_data ⇒ Object
Start character + data + checksum + stop character
42 43 44 45 46 47 |
# File 'lib/barcodes/symbology/code11.rb', line 42 def formatted_data checksum = self.checksum unless checksum.nil? @start_character + @data + checksum + @stop_character end end |