Class: Barcodes::Symbology::Ean13

Inherits:
Ean
  • Object
show all
Defined in:
lib/barcodes/symbology/ean13.rb

Overview

This class represents the EAN13 symbology EAN13 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

Methods inherited from Ean

#caption_data, charset, #checksum, #encoded_data, left_hand_even, left_hand_odd, parity, #quiet_zone_width, right_hand, valueset

Methods inherited from Base

#caption_data, charset, #encoded_data, #height, #quiet_zone_width, valueset, #width

Constructor Details

#initialize(args = {}) ⇒ Ean13

Creates a new Ean13 instance



19
20
21
22
23
24
25
# File 'lib/barcodes/symbology/ean13.rb', line 19

def initialize(args={})
  unless args.has_key? :data
    args[:data] = '012345678999'
  end
  
  super(args)
end

Instance Method Details

#formatted_dataObject

Returns start character + data + center character + data + checksum + stop character



28
29
30
# File 'lib/barcodes/symbology/ean13.rb', line 28

def formatted_data
  @start_character + @data[0..6] + @center_character + @data[7..12] + self.checksum + @stop_character
end

#valid?Boolean

Determines whether or not the barcode data to be encoded is valid. Data length must be exactly 12 digits



35
36
37
# File 'lib/barcodes/symbology/ean13.rb', line 35

def valid?
  return self.data.length == 12 ? true : false
end