Class: PennMARC::Location

Inherits:
Helper
  • Object
show all
Defined in:
lib/pennmarc/helpers/location.rb

Overview

Methods that return Library and Location values from Alma enhanced MARC fields

Constant Summary collapse

WEB_LOCATION_CODE =
'web'

Constants included from Util

Util::TRAILING_PUNCTUATIONS_PATTERNS

Class Method Summary collapse

Methods included from Util

#append_relator, #append_trailing, #datafield_and_linked_alternate, #field_defined?, #field_or_its_linked_alternate?, #join_and_squish, #join_subfields, #linked_alternate, #linked_alternate_not_6_or_8, #no_subfield_value_matches?, #prefixed_subject_and_alternate, #relator, #relator_join_separator, #relator_term_subfield, #remove_paren_value_from_subfield_i, #subfield_defined?, #subfield_in?, #subfield_not_in?, #subfield_undefined?, #subfield_value?, #subfield_value_in?, #subfield_value_not_in?, #subfield_values, #subfield_values_for, #substring_after, #substring_before, #translate_relator, #trim_punctuation, #trim_trailing, #trim_trailing!, #valid_subject_genre_source_code?

Class Method Details

.library(record, location_map: Mappers.location) ⇒ Array<String>

Retrieves library location from enriched marc ‘itm’ or ‘hld’ fields, giving priority to the item location over the holdings location. Returns item’s location if available. Otherwise, returns holding’s location. Enriched maps enriched marc fields and subfields created during Alma publishing.

Parameters:

  • record (MARC::Record)
  • location_map (Hash) (defaults to: Mappers.location)

    hash with location_code as key and location hash as value

Returns:

  • (Array<String>)

    Array of library locations retrieved from location_map

See Also:



17
18
19
# File 'lib/pennmarc/helpers/location.rb', line 17

def library(record, location_map: Mappers.location)
  location(record: record, location_map: location_map, display_value: 'library')
end

.location(record:, display_value:, location_map:) ⇒ Array<String>

Base method to retrieve location data from enriched marc ‘itm’ or ‘hld’ fields, giving priority to the item location over the holdings location. Returns item location if available. Otherwise, returns holdings location. Enriched maps enriched marc fields and subfields created during Alma publishing.

Parameters:

  • record (MARC::Record)
  • display_value (Symbol, String)

    field in location hash to retrieve

  • location_map (Hash)

    hash with location_code as key and location hash as value

Returns:

  • (Array<String>)

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pennmarc/helpers/location.rb', line 43

def location(record:, display_value:, location_map:)
  # get enriched marc location tag and relevant subfields
  enriched_location_tag_and_subfields(record) => { tag:, location_code_sf:, call_num_sf:, call_num_type_sf: }

  record.fields(tag).flat_map { |field|
    field.filter_map { |subfield|
      # skip unless subfield matches enriched marc tag subfield code
      next unless subfield.code == location_code_sf

      location_code = subfield.value

      next if location_code_to_ignore?(location_map, location_code)

      override = if display_value.to_sym == :specific_location
                   specific_location_override(location_code: location_code, field: field,
                                              call_num_sf: call_num_sf, call_num_type_sf: call_num_type_sf)
                 end

      override || location_map[location_code.to_sym][display_value.to_sym]
    }.flatten.compact_blank
  }.uniq
end

.specific_location(record, location_map: Mappers.location) ⇒ Array<String>

Retrieves the specific location from enriched marc ‘itm’ or ‘hld’ fields, giving priority to the item location over the holdings location. Returns item library location if available. Otherwise, returns holdings library location. Enriched maps enriched marc fields and subfields created during Alma publishing.

Parameters:

  • record (MARC::Record)
  • location_map (Hash) (defaults to: Mappers.location)

    hash with location_code as key and location hash as value

Returns:

  • (Array<String>)

    Array of specific locations retrieved from location_map

See Also:



30
31
32
# File 'lib/pennmarc/helpers/location.rb', line 30

def specific_location(record, location_map: Mappers.location)
  location(record: record, location_map: location_map, display_value: 'specific_location')
end