Class: Barby::EAN8

Inherits:
EAN13 show all
Defined in:
lib/barby/barcode/ean_8.rb

Overview

EAN-8 is a sub-set of EAN-13, with only 7 (8) digits

Constant Summary collapse

FORMAT =
/^\d{7}$/

Constants inherited from EAN13

Barby::EAN13::CENTER, Barby::EAN13::LEFT_ENCODINGS_EVEN, Barby::EAN13::LEFT_ENCODINGS_ODD, Barby::EAN13::LEFT_PARITY_MAPS, Barby::EAN13::RIGHT_ENCODINGS, Barby::EAN13::START, Barby::EAN13::STOP

Instance Attribute Summary

Attributes inherited from EAN13

#data

Instance Method Summary collapse

Methods inherited from EAN13

#center_encoding, #characters, #checksum, #checksum_encoding, #data_with_checksum, #encoding, #initialize, #left_encoding, #left_encodings, #numbers, #numbers_with_checksum, #odd_and_even_numbers, #right_encoding, #right_encodings, #start_encoding, #stop_encoding, #to_s, #upc?, #weighted_sum

Methods inherited from Barcode

#encoding, #method_missing, #outputter_class_for, #outputter_for, outputters, register_outputter, #to_s, #two_dimensional?

Constructor Details

This class inherits a constructor from Barby::EAN13

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Barby::Barcode

Instance Method Details

#left_numbersObject



11
12
13
# File 'lib/barby/barcode/ean_8.rb', line 11

def left_numbers
  numbers[0,4]
end

#left_parity_mapObject

Left-hand digits are all encoded using odd parity



21
22
23
# File 'lib/barby/barcode/ean_8.rb', line 21

def left_parity_map
  [:odd, :odd, :odd, :odd]
end

#right_numbersObject



15
16
17
# File 'lib/barby/barcode/ean_8.rb', line 15

def right_numbers
  numbers_with_checksum[4,4]
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/barby/barcode/ean_8.rb', line 26

def valid?
  data =~ FORMAT
end