Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Provides EAN, ISBN, and ASIN classes in Ruby

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 bookland.gemspec
README.md

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

:metal::metal:

Something went wrong with that request. Please try again.