From: atz Date: Thu, 2 Sep 2010 18:47:35 +0000 (+0000) Subject: Utility for ISBN10->ISBN13 upconversion X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=616ab5e1cc0646cef541dd400ff12aa2d0ac29d3;p=evergreen%2Fbjwebb.git Utility for ISBN10->ISBN13 upconversion git-svn-id: svn://svn.open-ils.org/ILS/trunk@17449 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/ISBN.pm b/Open-ILS/src/perlmods/OpenILS/Utils/ISBN.pm new file mode 100644 index 000000000..34eed663a --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Utils/ISBN.pm @@ -0,0 +1,96 @@ +package OpenILS::Utils::ISBN; + +# --------------------------------------------------------------- +# Copyright (C) 2010 Equinox Software, Inc +# Author: Joe Atzberger +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# --------------------------------------------------------------- + +use strict; +use warnings; + +use Business::ISBN; + +use base qw/Exporter/; +our $VERSION = '0.01'; +our @EXPORT_OK = qw/isbn_upconvert/; + +# Jason Stephenson at Merrimack Valley Library Consortium +# Dan Scott at Laurentian University + +sub isbn_upconvert { + my $in = @_ ? shift : return; + my $pretty = @_ ? shift : 0; + $in =~ s/\s*//g; + $in =~ s/-//g; + length($in) or return; + my $isbn = Business::ISBN->new($in) or return; + $isbn->fix_checksum() if $isbn->is_valid_checksum() == Business::ISBN::BAD_CHECKSUM; + $isbn->is_valid() or return; + return $pretty ? $isbn->as_isbn13->as_string : $isbn->as_isbn13->isbn; +} + +1; +__END__ + +For example, if you have a file isbns.txt with these lines: + +1598884093 + 1598884093 + 15 988 840 93 +0446357197 + 0 446 3 5 7 1 9 7 + 0 446 3 5 7 1 9 1 +0596526857 +0786222735 +0446360015 +0446350109 +0446314129 +0439139597 +0743294394 +159143047X +1590203097 +075480965X +0393048799 +0446831832 +0446310069 +1598883275 +0446313033 +0446360279 + +And you run: + perl -pe 'use OpenILS::Utils::ISBN qw/isbn_upconvert/; $_ = isbn_upconvert($_) . "\n";'