View | Details | Raw Unified | Return to bug 6281
Collapse All | Expand All

(-)a/C4/ClassSortRoutine/LCC.pm (-13 / +6 lines)
Lines 1-6 Link Here
1
package C4::ClassSortRoutine::LCC;
1
package C4::ClassSortRoutine::LCC;
2
2
3
# Copyright (C) 2007 LibLime
3
# Copyright (C) 2007 LibLime
4
# Copyright (C) 2012 Equinox Software, Inc.
4
# 
5
# 
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 19-24 package C4::ClassSortRoutine::LCC; Link Here
19
20
20
use strict;
21
use strict;
21
use warnings;
22
use warnings;
23
use Library::CallNumber::LC;
22
24
23
use vars qw($VERSION);
25
use vars qw($VERSION);
24
26
Lines 50-68 sub get_class_sort_key { Link Here
50
52
51
    $cn_class = '' unless defined $cn_class;
53
    $cn_class = '' unless defined $cn_class;
52
    $cn_item  = '' unless defined $cn_item;
54
    $cn_item  = '' unless defined $cn_item;
53
    my $key = uc "$cn_class $cn_item";
55
    my $call_number = Library::CallNumber::LC->new(uc "$cn_class $cn_item");
54
    $key =~ s/^\s+//;
56
    return '' unless defined $call_number;
55
    $key =~ s/\s+$//;
57
    my $key = $call_number->normalize();
56
    $key =~ s/^[^\p{IsAlnum}\s.]//g;
58
    $key = '' unless defined $key;
57
    $key =~ s/^([A-Z]+)/$1 /;
58
    $key =~ s/(\.[A-Z])/ $1/g;
59
    # handle first digit group
60
    $key =~ s/(\d+)/sprintf("%-05.5d", $1)/xe;
61
    $key =~ s/\s+/_/g;
62
    $key =~ s/\./_/g;
63
    $key =~ s/__/_/g;
64
    $key =~ s/[^\p{IsAlnum}_]//g;
65
66
    return $key;
59
    return $key;
67
60
68
}
61
}
(-)a/t/ClassSortRoutine_LCC.t (-7 / +6 lines)
Lines 14-30 BEGIN { Link Here
14
14
15
#Obvious cases
15
#Obvious cases
16
is(C4::ClassSortRoutine::LCC::get_class_sort_key(), "", "No arguments returns an empty string");
16
is(C4::ClassSortRoutine::LCC::get_class_sort_key(), "", "No arguments returns an empty string");
17
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A_B", "Arguments 'a','b' return 'A_B'");
17
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A B", "Arguments 'a','b' return 'A B'");
18
18
19
#spaces in arguements
19
#spaces in arguements
20
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B_", "Arguments ' ','b' return 'B_'");
20
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B", "Arguments ' ','b' return 'B'");
21
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A_", "Arguments 'a',' ' return 'A_'");
21
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A", "Arguments 'a',' ' return 'A'");
22
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','    '), "", "Arguments ' ','    ' return ''");
22
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','    '), "", "Arguments ' ','    ' return ''");
23
23
24
#'funky cases' based on regex in code
24
#'funky cases' based on regex in code
25
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "_B", "Arguments '.','b' return '_B'");
25
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "", "Arguments '.','b' return ''");
26
is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "_______", "Arguments '....','........' return '_______'");
26
is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "", "Arguments '....','........' return ''");
27
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "__", "Arguments '.','.' return '__'");
27
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "", "Arguments '.','.' return ''");
28
28
29
# list of example call numbers -- these
29
# list of example call numbers -- these
30
# are intentionally in the _reverse_ of
30
# are intentionally in the _reverse_ of
31
- 

Return to bug 6281