Class: Barby::Bookland

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

Overview

Bookland barcodes are EAN-13 barcodes with number system 978 (hence “Bookland”). The data they encode is an ISBN with its check digit removed. This is a convenience class that takes an ISBN no instead of “pure” EAN-13 data.

Constant Summary collapse

BOOKLAND_NUMBER_SYSTEM =
'978'

Constants inherited from EAN13

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EAN13

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

Methods inherited from Barcode

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

Constructor Details

#initialize(isbn) ⇒ Bookland

Returns a new instance of Bookland.

Raises:

  • (ArgumentError)


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

def initialize(isbn)
  self.isbn = isbn
  raise ArgumentError, 'data not valid' unless valid?
end

Dynamic Method Handling

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

Instance Attribute Details

#isbnObject

Returns the value of attribute isbn.



13
14
15
# File 'lib/barby/barcode/bookland.rb', line 13

def isbn
  @isbn
end

Instance Method Details

#dataObject



20
21
22
# File 'lib/barby/barcode/bookland.rb', line 20

def data
  BOOKLAND_NUMBER_SYSTEM+isbn_only
end

#isbn_onlyObject

Removes any non-digit characters, number system and check digit from ISBN, so “978-82-92526-14-9” would result in “829252614”



26
27
28
29
30
31
32
33
# File 'lib/barby/barcode/bookland.rb', line 26

def isbn_only
  s = isbn.gsub(/[^0-9]/, '')
  if s.size > 10#Includes number system
    s[3,9]
  else#No number system, may include check digit
    s[0,9]
  end
end