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/979 (hence “Bookland”). The data they encode is an ISBN with its check digit removed. This is a convenience class that takes an ISBN number instead of “pure” EAN-13 data.

#These are all the same:
barcode = Bookland.new('978-0-306-40615-7')
barcode = Bookland.new('978-0-306-40615')
barcode = Bookland.new('0-306-40615-7')
barcode = Bookland.new('0-306-40615')

If a prefix is not given, a default of 978 is used.

Defined Under Namespace

Classes: ISBN

Constant Summary

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 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

isbn should be an ISBN number string, with or without an EAN prefix and an ISBN checksum non-number formatting like hyphens or spaces are ignored

If a prefix is not given, a default of 978 is used.

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/barby/barcode/bookland.rb', line 24

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 Method Details

#dataObject



29
30
31
# File 'lib/barby/barcode/bookland.rb', line 29

def data
  isbn.isbn
end

#isbnObject

An instance of ISBN



38
39
40
# File 'lib/barby/barcode/bookland.rb', line 38

def isbn
  @isbn
end

#isbn=(isbn) ⇒ Object



33
34
35
# File 'lib/barby/barcode/bookland.rb', line 33

def isbn=(isbn)
  @isbn = ISBN.new(isbn)
end