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

(-)a/Koha/Util/Normalize.pm (+96 lines)
Line 0 Link Here
1
package Koha::Util::Normalize;
2
3
# Copyright 2016 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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 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 Modern::Perl;
21
22
=head1 NAME
23
24
Koha::Util::Normalize - utility class with string normalization routines
25
26
=head1 METHODS
27
28
=head2 default
29
30
Default normalization function
31
32
=cut
33
34
sub default {
35
36
    my $string = uc shift;
37
38
    $string =~ s/[.;:,\]\[\)\(\/'"]//g;
39
    $string =~ s/^\s+//;
40
    $string =~ s/\s+$//;
41
    $string =~ s/\s+/ /g;
42
43
    return $string;
44
}
45
46
=head2 remove_spaces
47
48
Normalization function removing spaces
49
50
=cut
51
52
sub remove_spaces {
53
54
    my $string = shift;
55
56
    $string =~ s/\s+//g;
57
58
    return $string;
59
}
60
61
=head2 upper_case
62
63
Normalization function converting characters into upper-case
64
65
=cut
66
67
sub upper_case {
68
69
    my $string = uc shift;
70
71
    return $string;
72
}
73
74
=head2 lower_case
75
76
Normalization function converting characters into lower-case
77
78
=cut
79
80
sub lower_case {
81
82
    my $string = lc shift;
83
84
    return $string;
85
}
86
87
1;
88
__END__
89
90
=head1 AUTHOR
91
92
Koha Development Team <http://koha-community.org/>
93
94
Tomas Cohen Arazi <tomascohen@theke.io>
95
96
=cut
(-)a/t/Koha/Util/Normalize.t (-1 / +67 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 5;
21
22
BEGIN {
23
    use_ok('Koha::Util::Normalize');
24
}
25
26
subtest 'default() normalizer' => sub {
27
28
    plan tests => 1;
29
30
    my $string = '  .; kY[]:,  (l)/E\'"';
31
32
    is( Koha::Util::Normalize::default( $string ), 'KY LE',
33
        'The default normalizer removes: .;:,][)(/\'" and shifts characters upper-case.
34
         Also removes spaces from the beginning and ending, and replaces multiple spaces with a single one.' );
35
};
36
37
subtest 'remove_spaces() normalizer' => sub {
38
39
    plan tests => 1;
40
41
    my $string = '  .; kY[]:,  (l)/E\'"';
42
43
    is( Koha::Util::Normalize::remove_spaces( $string ), '.;kY[]:,(l)/E\'"',
44
        'The \'remove_spaces\' normalizer removes all spaces' );
45
};
46
47
subtest 'upper_case() normalizer' => sub {
48
49
    plan tests => 1;
50
51
    my $string = '  .; kY[]:,  (l)/E\'"';
52
53
    is( Koha::Util::Normalize::upper_case( $string ), '  .; KY[]:,  (L)/E\'"',
54
        'The \'upper_case\' normalizer removes all spaces' );
55
};
56
57
subtest 'lower_case() normalizer' => sub {
58
59
    plan tests => 1;
60
61
    my $string = '  .; kY[]:,  (l)/E\'"';
62
63
    is( Koha::Util::Normalize::lower_case( $string ), '  .; ky[]:,  (l)/e\'"',
64
        'The \'lower_case\' normalizer removes all spaces' );
65
};
66
67
1;

Return to bug 17302