Make titles understand compressed holdings
authorDan Wells <dbw2@calvin.edu>
Tue, 17 Sep 2013 21:02:54 +0000 (17:02 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 17 Sep 2013 21:05:21 +0000 (17:05 -0400)
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Utils/MFHD/Holding.pm

index c9dc00b..915715d 100644 (file)
@@ -56,13 +56,17 @@ sub new {
             }
             if ($key =~ /[a-h]/) {
                 # Enumeration specific details of holdings
-                $self->{_mfhdh_FIELDS}->{$key}{UNIT_TITLE} = undef;
+                $self->{_mfhdh_FIELDS}->{$key}{UNIT_TITLES} = undef;
                 $last_enum = $key;
             }
         } elsif ($key eq 'o') {
             warn '$o specified prior to first enumeration'
               unless defined($last_enum);
-            $self->{_mfhdh_FIELDS}->{$last_enum}->{UNIT_TITLE} = $val;
+            if ($self->{_mfhdh_COMPRESSED}) {
+                $self->{_mfhdh_FIELDS}->{$key}{UNIT_TITLES} = [split(/\-/, $val, -1)];
+            } else {
+                $self->{_mfhdh_FIELDS}->{$key}{UNIT_TITLES} = [$val];
+            }
             $last_enum = undef;
         } elsif ($key =~ /[npq]/) {
             $self->{_mfhdh_DESCR}->{$key} = $val;
@@ -135,11 +139,12 @@ sub field_values {
 # Given a field key, returns a unit title (if there is one), or undef
 # if there isn't
 #
-sub unit_title {
+sub unit_titles {
     my ($self, $key) = @_;
 
     if (exists $self->fields->{$key}) {
-        return $self->fields->{$key}{UNIT_TITLE};
+        my @titles = $self->fields->{$key}{UNIT_TITLES};
+        return \@titles;
     } else {
         return;
     }
@@ -376,7 +381,7 @@ sub format_single_enum {
 
     $skip_sep ||= ($key eq 'a');
     return ($skip_sep ? '' : $sep) . $capstr . $holding_values->{$key} .
-        ($self->unit_title($key) ? ' ' . $self->unit_title($key) : '');
+        (($holding_values->{$key . '_title'}) ? ' ' . $holding_values->{$key . '_title'} : '');
 }
 
 #
@@ -466,6 +471,8 @@ sub format {
     foreach my $key (keys %$subfields) {
         ($holding_start{$key}, $holding_end{$key}) =
           @{$self->field_values($key)};
+        ($holding_start{$key . '_title'}, $holding_end{$key . '_title'}) =
+          @{$self->unit_titles($key)};
     }
 
     if ($self->is_compressed) {