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

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Nov 2 16:58:05 EST 2008


Author: djfiander
Date: 2008-11-02 16:58:00 -0500 (Sun, 02 Nov 2008)
New Revision: 11025

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
Log:
The first kick at predicting: figuring out what the next issue
number is for a really simple case. Doesn't do anything at all
related to the calendar, and doesn't cope with continuously
numbered issues.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2008-11-02 21:56:16 UTC (rev 11024)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2008-11-02 21:58:00 UTC (rev 11025)
@@ -94,9 +94,68 @@
     return $str;
 }
 
+# next: Given a holding statement, return a hash containing the 
+# enumeration values for the next issues, whether we hold it or not
+#
 sub next {
     my $self = shift;
     my $caption = $self->{CAPTION};
+    my $next = {};
+
+    foreach my $key ('a' .. 'f') {
+	last if !exists $self->{ENUMS}->{$key};
+	$next->{$key} = $self->{ENUMS}->{$key}->{HOLDINGS};
+    }
+    foreach my $key (reverse('a'.. 'f')) {
+	next if !exists $next->{$key};
+	if (!exists $caption->{ENUMS}->{$key}) {
+	    # Just assume that it increments continuously and give up
+	    warn "Holding data exists for $key, but no caption specified";
+	    $next->{$key} += 1;
+	    last;
+	}
+
+	my $cap = $caption->{ENUMS}->{$key};
+	if ($cap->{RESTART} && $cap->{COUNT}
+	    && ($next->{$key} eq $cap->{COUNT})) {
+	    $next->{$key} = 1;
+	    # I increment the next higher level of enumeration by continuing
+	    # the loop.
+	} else {
+	    # If I don't need to "carry" beyond here, then I just increment
+	    # this level of the enumeration and stop looping, since the
+	    # "next" hash has been initialized with the current values
+
+	    # NOTE: This DOES NOT take into account the incrementing
+	    # of enumerations based on the calendar. (eg: The Economist)
+	    $next->{$key} += 1;
+	    last;
+	}
+    }
+
+    return($next);
 }
 
+# match($pat): check to see if $self matches the enumeration passed
+# in as $pat. This is expected to be used in conjunction with the next()
+# function defined above.
+#
+#
+#
+sub match {
+    my $self = shift;
+    my $pat = shift;
+
+    foreach my $key ('a'..'f') {
+	# If a subfield exists in $self but not in $pat, or vice versa
+	# or if the field has different values, then fail
+	if (exists($self->{ENUMS}->{$key}) != exists($pat->{$key})
+	    || (exists $pat->{$key}
+		&& ($self->{ENUMS}->{$key}->{HOLDINGS} ne $pat->{$key}))) {
+	    return 0;
+	}
+    }
+    return 1;
+}
+
 1;



More information about the open-ils-commits mailing list