Project

bookland

0.01
No commit activity in last 3 years
No release in over 3 years
Provides EAN, ISBN, and ASIN classes and validators in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 4.2
>= 0
 Project Readme

Bookland

Bookland is a fictitious country that exists solely for the purposes of non-geographically cataloguing books in the otherwise geographically keyed EAN coding system.

Usage

Bookland provides EAN and ISBN classes:

include 'bookland'

# functional
EAN.valid?('0814916013890') # => true
ISBN.valid?('9780262011532') # => true

# oo
isbn = ISBN.new('9780262011532')
isbn.valid? # => true

Bookland also comes with an ASIN class:

isbn = '9780262011532'
asin = ASIN.from_isbn(isbn) # => "0262011530"
ASIN.to_isbn(asin) # => "9780262011532"

Caveat: ASIN does not calculate the checksum digit for propietary ASINs. If you happen to break their algo, ping me.

All three classes expose a class-level calculate_checksum_digit method:

data_digits = [9, 7, 8, 0, 2, 6, 2, 1, 1, 5, 3]
ISBN.calculate_checksum_digit(data_digits) # => 2

Bookland includes custom EAN, ISBN, and ASIN validators if Active Model is loaded. Use it like so:

class Book
  include ActiveModel::Model

  attr_accessor :isbn

  validates :isbn, isbn: true
end

🤘🤘