Class: PennMARC::Genre

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

Overview

Genre field values come from the 655, but for some contexts we are only interested in a subset of the declared terms in a record.

Constant Summary

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

.facet(record) ⇒ Array<String>

TODO:

the Genre facet in Franklin is pretty ugly. It could be cleaned up by limiting the subfields included here and cleaning up punctuation.

Note:

Prior to 5/2026, we only set Genre facet values for movies (videos) and manuscripts.

Genre values for faceting.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


52
53
54
55
56
57
58
# File 'lib/pennmarc/helpers/genre.rb', line 52

def facet(record)
  record.fields('655').filter_map { |field|
    next unless allowed_genre_field?(field)

    join_subfields field, &subfield_not_in?(%w[0 2 5 c])
  }.uniq
end

.search(record) ⇒ Array<String>

Genre values for searching. We’re less picky about what is included here to enable discovery via any included 655 data.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    array of genre values for search



13
14
15
16
17
# File 'lib/pennmarc/helpers/genre.rb', line 13

def search(record)
  record.fields('655').map { |field|
    join_subfields(field, &subfield_not_in?(%w[0 2 5 c]))
  }.uniq
end

.show(record) ⇒ Array<String>

TODO:

subfields e and w do not appear in the documentation for 655, but we give them special consideration here, what gives?

Note:

legacy method returns a link object

Genre values for display. We display Genre/Term values if they fulfill the following criteria:

- The field is in {https://www.oclc.org/bibformats/en/6xx/655.html MARC 655}. Or the field is in MARC 880 with
  subfield 6 including '655'.
 AND
  - Above fields have an indicator 2 value of: 0 (LSCH) or 4 (No source specified).
   OR
  - Above fields have a subfield 2 (ontology code) in the list of allowed values.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    array of genre values for display



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

def show(record)
  record.fields(%w[655 880]).filter_map { |field|
    next unless allowed_genre_field?(field)

    next if field.tag == '880' && no_subfield_value_matches?(field, '6', /^655/)

    subfields = %w[a b]
    sub_with_hyphens = field.find_all(&subfield_not_in?(%w[0 2 5 6 8 c e w])).map { |sf|
      sep = subfields.exclude?(sf.code) ? ' -- ' : ' '
      sep + sf.value
    }.join.lstrip
    "#{sub_with_hyphens} #{field.find_all(&subfield_in?(%w[e w])).join(' -- ')}".strip
  }.uniq
end