library_stdnums -- simple functions to check and normalize ISSN/ISBN/LCCN

These are a set of Module functions (not classes with methods!) that perform simple checksum verification and (when applicable) normalization on strings containing common library types (currently just ISBN, ISSN, and LCCN).

The code allows for some minimal crap (e.g., '1234-4568 online') will work fine. All returned ISBN/ISSN values are devoid any dashes; any trailing X for an ISBN/ISSN checkdigit will be uppercase and will always be returned as a one-digit string.

See the actual functions for more information than what's below.

ISBN

  isbn = StdNum::ISBN.normalize(goodISBN)
    # => a 13-digit ISBN with no dashes/spaces

  isbn = StdNum::ISBN.normalize(badISBN)
    # => nil (if it's not an ISBN or the checkdigit is bad)

  tenDigit = StdNum::ISBN.convert_to_10(isbn13)
  thirteenDigit = StdNum::ISBN.convert_to_13(isbn10)

  thirteenDigit,tenDigit = StdNum::ISBN.allNormalizedValues(issn)
    # => array of the ten and thirteen digit isbns if valid; 
    #    an empty array if not

  digit = StdNum::ISBN.checkdigit(isbn)
    # => 0..9 (for isbn13) or 0..9,X (for isbn10)

  if StdNum::ISBN.valid?(isbn)
    puts "#{isbn} has a valid checkdigit"
  end

ISSN

  issn = StdNum::ISSN.normalize(issn)
  #  => the cleaned-up issn if valid; nil if not

  digit = StdNum::ISSN.checkdigit(issn)
  #  => 0..9 or X

  if StdNum::ISSN.valid?(issn)
    puts "#{issn} has a valid checkdigit"
  end

LCCN

LCCNs are normalized according to the algorithm at http://www.loc.gov/marc/lccn-namespace.html#syntax


  lccn = StdNum::LCCN.normalize(rawlccn)
  #  => either the normalized lccn, or nil if it has bad syntax

  if StdNum::LCCN.valid?(rawlccn) {
    puts "#{rawlccn} is valid"
  }

== CHANGES

== Note on Patches/Pull Requests

== Copyright

Copyright (c) 2010 Bill Dueber. See LICENSE for details.