Class: Barcodes::Symbology::Ean8
- Defined in:
- lib/barcodes/symbology/ean8.rb
Overview
This class represents the EAN8 symbology EAN8 can encode only numbers 0-9
More info: en.wikipedia.org/wiki/International_Article_Number_(EAN)
Instance Attribute Summary
Attributes inherited from Base
#alpha, #bar_height, #bar_width, #caption_height, #caption_size, #captioned, #color, #data
Instance Method Summary collapse
-
#encoded_data ⇒ Object
Encodes data into 1’s and 0’s.
-
#formatted_data ⇒ Object
Returns start character + data + center character + data + checksum + stop character.
-
#initialize(args = {}) ⇒ Ean8
constructor
Creates a new Ean13 instance.
-
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid.
Methods inherited from Ean
#caption_data, charset, #checksum, left_hand_even, left_hand_odd, parity, #quiet_zone_width, right_hand, valueset
Methods inherited from Base
#caption_data, charset, #height, #quiet_zone_width, valueset, #width
Constructor Details
#initialize(args = {}) ⇒ Ean8
Creates a new Ean13 instance
19 20 21 22 23 24 25 |
# File 'lib/barcodes/symbology/ean8.rb', line 19 def initialize(args={}) unless args.has_key? :data args[:data] = '0123456' end super(args) end |
Instance Method Details
#encoded_data ⇒ Object
Encodes data into 1’s and 0’s
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/barcodes/symbology/ean8.rb', line 33 def encoded_data if self.valid? formatted_data = self.formatted_data encoded_data = "" index = 0 formatted_data.each_byte do |char| if char.chr == 'S' encoded_data += "101" elsif char.chr == 'C' encoded_data += "01010" else if index < 6 encoded_data += self._encode_character_with_parity(char, '1') else encoded_data += self._encode_character_with_right_hand(char) end end index += 1 end encoded_data end end |
#formatted_data ⇒ Object
Returns start character + data + center character + data + checksum + stop character
28 29 30 |
# File 'lib/barcodes/symbology/ean8.rb', line 28 def formatted_data @start_character + @data[0..3] + @center_character + @data[4..6] + self.checksum + @stop_character end |
#valid? ⇒ Boolean
Determines whether or not the barcode data to be encoded is valid. Data length must be exactly 7 digits
59 60 61 |
# File 'lib/barcodes/symbology/ean8.rb', line 59 def valid? return self.data.length == 7 ? true : false end |