Add code to test if current record's holdings can be
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 5 Nov 2008 02:55:23 +0000 (02:55 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 5 Nov 2008 02:55:23 +0000 (02:55 +0000)
compressed. See MFHD standard: "853-855 Captions and Pattern -
General Information", "Input Conventions" section.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@11063 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm

index 04df9a5..42911c4 100755 (executable)
@@ -2,6 +2,7 @@ package MFHD;
 use strict;
 use integer;
 use Carp;
+use Data::Dumper;
 
 use MARC::Record;
 use MFHD::Caption;
@@ -13,6 +14,7 @@ sub new {
     my $self = {};
     my $rec = shift;
 
+    $self->{RECORD} = $rec;
     $self->{CAPTIONS} = {};
 
     foreach my $field ('853', '854', '855') {
@@ -55,6 +57,46 @@ sub new {
     return $self;
 }
 
+# 
+# validate_captions: confirm that fields specified for holdings
+# data all have captions assigned to them
+# 
+sub validate_captions {
+    my $self = shift;
+
+    foreach my $cap_fieldno ('853' .. '855') {
+       foreach my $cap_id ($self->captions($cap_fieldno)) {
+           my $enum_fieldno;
+           ($enum_fieldno = $cap_fieldno) =~ s/5/6/;
+           foreach my $enum ($self->holdings($enum_fieldno, $cap_id)) {
+               foreach my $key (keys %{$enum->{ENUMS}}) {
+                   if (!exists $enum->{CAPTION}->{ENUMS}->{$key}) {
+                       print "$key doesn't exist: ", Dumper($enum);
+                       return 0;
+                   }
+               }
+           }
+       }
+       return 1;
+    }
+}
+
+sub compressible {
+    my $self = shift;
+    my $leader = $self->{RECORD}->leader;
+    my $holdings_level = substr($leader, 17, 1);
+
+    # Can only compress level 4 detailed holdings
+    # or detailed holdings with piece designation
+    return 0 unless (($holdings_level == 4) || ($holdings_level = 5));
+
+    # Can only compress if fields specified in each enumeration are
+    # defined in the corresponding caption
+    return 0 unless $self->validate_captions;
+
+    return 1;
+}
+
 sub captions {
     my $self = shift;
     my $field = shift;