Class: Barcodes::Symbology::UpcA

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

Overview

This class represents the UPC-A symbology UPC-A can encode only numbers 0-9

More info: en.wikipedia.org/wiki/Universal_Product_Code

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 = {}) ⇒ UpcA

Creates a new UpcA instance



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

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

Instance Method Details

#formatted_dataObject

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



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

def formatted_data
  @start_character + '0' + @data[0..5] + @center_character + @data[6..10] + self.checksum + @stop_character
end

#valid?Boolean

Validates barcode using provided data Data length must be 11 digits

Returns:

  • (Boolean)


34
35
36
# File 'lib/barcodes/symbology/upca.rb', line 34

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