Link Here
|
|
|
1 |
package Koha::MetadataExtractor; |
2 |
|
3 |
# Copyright ByWater Solutions 2023 |
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 |
=head1 NAME |
21 |
|
22 |
Koha::MetadataExtractor - Extract specific metadata from MARC::Record objects |
23 |
|
24 |
=cut |
25 |
|
26 |
use Modern::Perl; |
27 |
|
28 |
use Koha::Exceptions; |
29 |
use List::MoreUtils qw( any ); |
30 |
|
31 |
=head1 API |
32 |
|
33 |
=head2 Class methods |
34 |
|
35 |
=head3 new |
36 |
|
37 |
my $extractor = Koha::MetadataExtractor->new; |
38 |
|
39 |
Constructor for the I<Koha::MetadataExtractor> class. |
40 |
|
41 |
=cut |
42 |
|
43 |
sub new { |
44 |
my ($class) = @_; |
45 |
my $self = { extractors => {} }; |
46 |
|
47 |
return |
48 |
bless $self, |
49 |
$class; |
50 |
} |
51 |
|
52 |
=head2 get_normalized_upc |
53 |
|
54 |
my $normalized_upc = $extractor->get_normalized_upc( { record => $record, schema => $schema } ); |
55 |
|
56 |
Returns the normalized UPC for the passed I<$record>. |
57 |
|
58 |
=cut |
59 |
|
60 |
sub get_normalized_upc { |
61 |
my ( $self, $params ) = @_; |
62 |
|
63 |
Koha::Exceptions::MissingParameter->throw( parameter => 'record' ) |
64 |
unless $params->{record}; |
65 |
|
66 |
return $self->get_extractor( { schema => $params->{schema} } )->get_normalized_upc( $params->{record} ); |
67 |
} |
68 |
|
69 |
=head2 Internal methods |
70 |
|
71 |
=head3 get_extractor |
72 |
|
73 |
my $extractor = $self->get_extractor( { schema => $schema } ); |
74 |
|
75 |
Returns the cached extractor for the specified I<$schema>. |
76 |
|
77 |
=cut |
78 |
|
79 |
sub get_extractor { |
80 |
my ( $self, $params ) = @_; |
81 |
|
82 |
my $schema = $params->{schema}; |
83 |
|
84 |
Koha::Exceptions::MissingParameter->throw( parameter => 'schema' ) |
85 |
unless $schema; |
86 |
|
87 |
my $valid_schemas = { 'MARC21' => 1, 'UNIMARC' => 1 }; |
88 |
|
89 |
Koha::Exceptions::WrongParameter->throw( name => 'schema', value => $schema ) |
90 |
unless $valid_schemas->{$schema}; |
91 |
|
92 |
unless ( $self->{extractors}->{$schema} ) { |
93 |
my $extractor_class = "Koha::MetadataExtractor::MARC::$schema"; |
94 |
eval "require $extractor_class"; |
95 |
$self->{extractors}->{$schema} = $extractor_class->new; |
96 |
} |
97 |
|
98 |
return $self->{extractors}->{$schema}; |
99 |
} |
100 |
|
101 |
=head1 AUTHOR |
102 |
|
103 |
Tomas Cohen Arazi, E<lt>tomascohen@theke.ioE<gt> |
104 |
|
105 |
=cut |
106 |
|
107 |
1; |
108 |
|
109 |
__END__ |