Project

petrarca

0.0
No release in over a year
Library to manipulate ISBN numbers for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

Petrarca

This library Petrarca provides some utility functions to manipulate ISBN numbers:

  • Validation
  • Calculate check digit
  • Mutual conversion of ISBN-13 and ISBN-10
  • Hyphenation / Dehyphenation
  • Split to an array that includes ISBN segments

All functions support both ISBN-13 and ISBN-10.

All ranges of registration groups and registrants are supported. Those depend indirectly on data published by the International ISBN agency through 'isbnranges' gem.

In version 1.0.0, the range files have been removed. Instead, the data provided by 'isbnranges' gem is used. See https://github.com/takatoh/ISBNRanges for more information.

No longer update just for range files.

Installation

Add this line to your application's Gemfile:

gem "petrarca"

And then execute:

$ bundle

Or install it yourself as:

$ gem install petrarca

Usage

irb(main):001:0> require "petrarca"
=> true
irb(main):002:0> Petrarca.valid?("978-4-8156-0644-2")
=> true
irb(main):003:0> Petrarca.calc_check_digit("978-4-8156-0644-2")
=> "2"
irb(main):004:0> Petrarca.to_10("978-4-8156-0644-2")
=> "4-8156-0644-7"
irb(main):005:0> Petrarca.to_13("4-8156-0644-7")
=> "978-4-8156-0644-2"
irb(main):006:0> Petrarca.hyphenate("9784815606442")
=> "978-4-8156-0644-2"
irb(main):007:0> Petrarca.dehyphenate("978-4-8156-0644-2")
=> "9784815605442"
irb(main):008:0> Petrarca.split("9784815606442")
=> ["978", "4", "8156", "0644", "2"]

Petrarca.dehyphenate and Petrarca.split are new in v0.6.0.

Accept Integer as ISBN, only if no - and X including. (New in v0.5.0)

irb(main):001:0> require 'petrarca'
=> true
irb(main):002:0> Petrarca.calc_check_digit(978481560644)
=> "2"
irb(main):003:0> Petrarca.to_10(9784815606442)
=> "4-8156-0644-7"
irb(main):004:0> Petrarca.to_13(4815606447)
=> "978-4-8156-0644-2"
irb(main):005:0> Petrarca.hyphenate(9784815606442)
=> "978-4-8156-0644-2"

If the ISBN is hyphenated, registration group and registrant are considered in Petrarca.valid?. The second example below has the invalid registrant.

irb(main):006:0> Petrarca.valid?("978-4-8156-0644-2")
=> true
irb(main):007:0> Petrarca.valid?("978-4-815-60644-2")
=> false

License

MIT License

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/takatoh/Petrarca.