From 89f0286c4fc5f20bd770c40d24d4d5ae48956dbd Mon Sep 17 00:00:00 2001 From: djfiander Date: Sun, 2 Nov 2008 21:58:00 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@11025 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Utils/MFHD/Holding.pm | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm index a29498d76a..21c3ca5dc0 100755 --- a/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm @@ -94,9 +94,68 @@ sub format { 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; -- 2.11.0