[open-ils-commits] r11063 - trunk/Open-ILS/src/perlmods/OpenILS/Utils

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Nov 4 21:55:24 EST 2008


Author: djfiander
Date: 2008-11-04 21:55:23 -0500 (Tue, 04 Nov 2008)
New Revision: 11063

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm
Log:
Add code to test if current record's holdings can be
compressed. See MFHD standard: "853-855 Captions and Pattern -
General Information", "Input Conventions" section.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm	2008-11-05 02:53:58 UTC (rev 11062)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD.pm	2008-11-05 02:55:23 UTC (rev 11063)
@@ -2,6 +2,7 @@
 use strict;
 use integer;
 use Carp;
+use Data::Dumper;
 
 use MARC::Record;
 use MFHD::Caption;
@@ -13,6 +14,7 @@
     my $self = {};
     my $rec = shift;
 
+    $self->{RECORD} = $rec;
     $self->{CAPTIONS} = {};
 
     foreach my $field ('853', '854', '855') {
@@ -55,6 +57,46 @@
     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;



More information about the open-ils-commits mailing list