Class: PennMARC::Classification

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

Overview

Generates library of congress and dewey classifications using call number data.

Constant Summary collapse

LOC_CALL_NUMBER_TYPE =

Subfield value that identifies Library of Congress call number

'0'
DEWEY_CALL_NUMBER_TYPE =

Subfield value that identifies Dewey call number

'1'
CLASSIFICATION_MAPS =

Hash that maps call number type to the appropriate mapper

{
  LOC_CALL_NUMBER_TYPE => Mappers.loc_classification,
  DEWEY_CALL_NUMBER_TYPE => Mappers.dewey_classification
}.freeze
TAGS =

Enriched MARC tags that hold classification data

[Enriched::Pub::ITEM_TAG, Enriched::Api::PHYS_INVENTORY_TAG].freeze

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_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_trailing, #trim_trailing!, #valid_subject_genre_source_code?

Class Method Details

.facet(record) ⇒ Array<String>

Parse classification values for faceting. We retrieve classification values from enriched MARC fields ‘itm’ or ‘AVA’ originating respectively from the Alma publishing process or from the Alma Api. We return the highest level LOC or Dewey classifications from each available call number, joining the class code with its title in a single string. See Enriched and Enriched::Api for more information on the enriched MARC fields.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    array of classifications

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pennmarc/helpers/classification.rb', line 30

def facet(record)
  record.fields(TAGS).flat_map { |field|
    call_number_type = subfield_values(field, call_number_type_sf(field))&.first
    call_numbers = subfield_values(field, call_number_sf(field))

    call_numbers.filter_map do |call_number|
      class_code = call_number[0]
      title = translate_classification(class_code, call_number_type)
      next if title.blank?

      format_facet(class_code, call_number_type, title)
    end
  }.uniq
end