filters in MDMP
authorShawn Boyette <sboyette@esilibrary.com>
Thu, 30 Apr 2009 01:49:35 +0000 (01:49 +0000)
committerShawn Boyette <sboyette@esilibrary.com>
Thu, 30 Apr 2009 01:49:35 +0000 (01:49 +0000)
Equinox-Migration/lib/Equinox/Migration/MapDrivenMARCXMLProc.pm
Equinox-Migration/lib/Equinox/Migration/SubfieldMapper.pm
Equinox-Migration/t/02-SubfieldMapper.t
Equinox-Migration/t/03-MapDrivenMARCXMLProc.t
Equinox-Migration/t/corpus/mdmpmap-05.txt
Equinox-Migration/t/corpus/sm0.txt

index 666551f..be96f46 100644 (file)
@@ -158,7 +158,11 @@ sub process_subs {
     my $dataf = $self->{data}{crec}{tags}[-1];
     my $field = $map->field($tag, $code);
 
-    # handle modifiers
+    # test filters
+    for my $filter ( @{$map->filters($field)} ) {
+        return if ($sub->text =~ /$filter/i);
+    }
+    # handle multi modifier
     if (my $mods = $map->mods($field)) {
         if ($mods->{multi}) {
             my $name = $tag . $code;
@@ -167,8 +171,11 @@ sub process_subs {
         }
     }
 
+    # if this were a multi field, it would be handled already. make sure its a singleton
     die "Multiple occurances of a non-multi field: $tag$code at rec ",
       ($self->{data}{rptr} + 1),"\n" if (defined $dataf->{uni}{$code});
+
+    # everything seems okay
     $dataf->{uni}{$code} = $sub->text;
 }
 
index cb8decd..68a545c 100644 (file)
@@ -236,7 +236,7 @@ sub generate {
                 $tok .= ' ' . shift @tokens
                   until ($tokens[0] =~ m/'$/);
                 $tok .= ' ' . shift @tokens;
-                $tok =~ s/^'//;
+                $tok =~ s/'//;
                 $tok =~ s/'$//;
             }
             if ($tok =~ m/^m:/)
index e248bc0..c948fdd 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -T
 
-use Test::More tests => 40;
+use Test::More tests => 41;
 #use Test::More qw(no_plan);
 use Equinox::Migration::SubfieldMapper;
 
@@ -96,4 +96,5 @@ is_deeply ($sm->mods('note'), { multi => 1}, 'multi');
 is_deeply ($sm->mods('note_alt'), { multi => 1, req => 1 }, 'multi, req');
 is_deeply ($sm->mods('date_a'), { foo => 1, bar => 1, quux => 1 });
 is_deeply ($sm->filters('date_a'), ['one two three']);
+is_deeply ($sm->filters('type'), ['foo']);
 
index d258a42..d01d6d1 100644 (file)
@@ -100,3 +100,13 @@ is_deeply ($rec->{tags}[0]{multi}{'999x'}, ['FICTION','FICTION2','FICTION3','FIC
            '999$x - multi');
 is ($mp->{data}{tmap}{250}, undef, 'tag map test 2a');
 is_deeply ($mp->{data}{tmap}{999}, [0], 'tag map test 2b');
+
+# map-05 is map-04 with a "no digits" filter on 999$x
+$mp = Equinox::Migration::MapDrivenMARCXMLProc->new( marcfile => 't/corpus/mdmp-0.txt',
+                                                     mapfile  => 't/corpus/mdmpmap-05.txt');
+is_deeply ($mp->{map}->filters('multi_field'), ['\d']);
+$rec = $mp->parse_record;
+$rec = $mp->parse_record;
+$rec = $mp->parse_record;
+$rec = $mp->parse_record;
+is_deeply ($rec->{tags}[0]{multi}{'999x'}, ['FICTION'], '999$x - multi no digits');
index 0e94bc9..ea96f71 100644 (file)
@@ -1,3 +1,3 @@
 call_num    999 a
-multi_field 999 x m:multi f:\\d
+multi_field 999 x m:multi f:\d
 edition     250 a
index 13875a1..7443b7c 100644 (file)
@@ -19,7 +19,7 @@ library         949 m
 library_alt     999 m
 note            949 o m:multi
 note_alt        999 o m:multi m:req
-type            949 t
+type            949 t f:foo
 type_alt        999 t
 date_a          949 v m:foo m:bar f:'one two three' m:quux
 date_a_alt      999 v