Bug 22357: Do not duplicate report rows if several reports exist
[koha.git] / C4 / ClassSplitRoutine / Dewey.pm
1 package C4::ClassSplitRoutine::Dewey;
2
3 # Copyright 2018 Koha Development Team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use C4::Debug;
23
24 =head1 NAME
25
26 C4::ClassSplitRoutine::Dewey - Dewey call number split method
27
28 =head1 SYNOPSIS
29
30 use C4::ClassSplitRoutine;
31
32 my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
33
34 =head1 FUNCTIONS
35
36 =head2 split_callnumber
37
38   my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
39
40 =cut
41
42 sub split_callnumber {
43     my ($cn_item) = @_;
44
45     my $possible_decimal =
46       qr/\d{3,}(?:\.\d+)?/;    # at least three digits for a DDCN
47
48     $cn_item =~ s/\///g
49       ; # in theory we should be able to simply remove all segmentation markers and arrive at the correct call number...
50     my (@lines) = $cn_item =~ m/
51         ^([-a-zA-Z]*\s?(?:$possible_decimal)?) # R220.3  CD-ROM 787.87 # will require extra splitting
52         \s+
53         (.+)                               # H2793Z H32 c.2 EAS # everything else (except bracketing spaces)
54         \s*
55         /x;
56     unless (@lines) {
57         warn sprintf( 'regexp failed to match string: %s', $cn_item );
58         push @lines, $cn_item;    # if no match, just push the whole string.
59     }
60
61     if ( $lines[0] =~ /^([-a-zA-Z]+)\s?($possible_decimal)$/ ) {
62         shift @lines;    # pull off the mathching first element, like example 1
63         unshift @lines, $1, $2;    # replace it with the two pieces
64     }
65
66     push @lines, split /\s+/,
67       pop @lines
68       ;    # split the last piece into an arbitrary number of pieces at spaces
69     $debug and print STDERR "split_ddcn array: ", join( " | ", @lines ), "\n";
70     return @lines;
71 }
72
73 1;
74
75 =head1 AUTHOR
76
77 Koha Development Team <http://koha-community.org/>
78
79 =cut