Skip to content

Commit

Permalink
added Sisis parser to Importer
Browse files Browse the repository at this point in the history
  • Loading branch information
jorol committed May 9, 2014
1 parent 898e8d1 commit 32266fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Catmandu/Importer/MAB2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Catmandu::Sane;
use Moo;
use MAB2::Parser::Disk;
use MAB2::Parser::RAW;
use MAB2::Parser::Sisis;
use MAB2::Parser::XML;

with 'Catmandu::Importer';
Expand All @@ -28,6 +29,9 @@ sub mab_generator {
elsif ( $type eq 'disk' ) {
$file = MAB2::Parser::Disk->new( $self->fh );
}
elsif ( $type eq 'sisis' ) {
$file = MAB2::Parser::Sisis->new( $self->fh );
}
else {
die "unknown format";
}
Expand All @@ -45,11 +49,11 @@ sub generator {
my ($self) = @_;

my $type = lc($self->type);
if ( $type =~ /raw|xml|disk$/ ) {
if ( $type =~ /disk|raw|sisis|xml$/ ) {
return $self->mab_generator;
}
else {
die "need MAB2 RAW or XML data";
die "need MAB2 Diskette, RAW, Sisis or XML data";
}
}

Expand Down Expand Up @@ -108,8 +112,8 @@ C<fh>, etc.) the importer can be configured with the following parameters:
=item type
Describes the MAB2 syntax variant. Supported values (case ignored) include the
default value C<xml> for MABxml, C<disk> for human-readable MAB2 serialization
and C<plus> or C<raw> for normalized MAB2.
default value C<xml> for MABxml, C<disk> for human-readable MAB2 serialization,
C<raw> for normalized MAB2 or C<sisis> for MAB Sisis data.
=back
Expand Down
8 changes: 8 additions & 0 deletions t/01-parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ ok($record->{record}->[0][3] eq '02020nM2.01200024 h', 'record leader' );
is_deeply($record->{record}->[1], ['001', ' ', '_', '47918-4'], 'first field');
ok($parser->next()->{_id} eq '54251-9', 'next record');

use MAB2::Parser::Sisis;
$parser = MAB2::Parser::Sisis->new( './t/mab2sisis.dat' );
isa_ok( $parser, 'MAB2::Parser::Sisis' );
$record = $parser->next();
ok($record->{_id} eq '2', 'record_id' );
is_deeply($record->{record}->[0], ['0000', ' ', '_', '2'], 'first field');
ok($parser->next()->{_id} eq '3', 'next record');

done_testing;

0 comments on commit 32266fe

Please sign in to comment.