replace references to defunct info email address
[koha.git] / C4 / ClassSortRoutine / Dewey.pm
1 package C4::ClassSortRoutine::Dewey;
2
3 # Copyright (C) 2007 LibLime
4
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22
23 use vars qw($VERSION);
24
25 # set the version for version checking
26 $VERSION = 3.00;
27
28 =head1 NAME 
29
30 C4::ClassSortRoutine::Dewey - generic call number sorting key routine
31
32 =head1 SYNOPSIS
33
34 use C4::ClassSortRoutine;
35
36 my $cn_sort = GetClassSortKey('Dewey', $cn_class, $cn_item);
37
38 =head1 FUNCTIONS
39
40 =head2 get_class_sort_key
41
42   my $cn_sort = C4::ClassSortRoutine::Dewey::Dewey($cn_class, $cn_item);
43
44 Generates sorting key using the following rules:
45
46 * Concatenates class and item part.
47 * Converts to uppercase.
48 * Removes leading and trailing whitespace and '/'
49 * Separates alphabetic prefix from the rest of the call number
50 * Splits into tokens on whitespaces and periods.
51 * Leaves first digit group as is.
52 * Converts second digit group to 15-digit long group, padded on right with zeroes.
53 * Converts each run of whitespace to an underscore.
54 * Removes any remaining non-alphabetical, non-numeric, non-underscore characters.
55
56 =cut
57
58 sub get_class_sort_key {
59     my ($cn_class, $cn_item) = @_;
60
61     $cn_class = '' unless defined $cn_class;
62     $cn_item  = '' unless defined $cn_item;
63     my $init = uc "$cn_class $cn_item";
64     $init =~ s/^\s+//;
65     $init =~ s/\s+$//;
66     $init =~ s!/!!g;
67     $init =~ s/^([\p{IsAlpha}]+)/$1 /;
68     my @tokens = split /\.|\s+/, $init;
69     my $digit_group_count = 0;
70     for (my $i = 0; $i <= $#tokens; $i++) {
71         if ($tokens[$i] =~ /^\d+$/) {
72             $digit_group_count++;
73             if (2 == $digit_group_count) {
74                 $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
75                 $tokens[$i] =~ tr/ /0/;
76             }
77         }
78     }
79     my $key = join("_", @tokens);
80     $key =~ s/[^\p{IsAlnum}_]//g;
81
82     return $key;
83
84 }
85
86 1;
87
88 =head1 AUTHOR
89
90 Koha Development Team <http://koha-community.org/>
91
92 =cut
93