Class: PennMARC::Relation

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

Overview

These MARC parsing method are grouped in virtue of their role as describing the relationship of a record to other records.

Constant Summary collapse

%w[700 710 711 730].freeze
CONTAINS_FIELDS =
%w[700 710 711 730 740].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, #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

.constituent_unit_show(record) ⇒ Array

Get “Constituent Unit” values from MARC 774. Include subfield values in i, a, s and t.



88
89
90
91
92
93
94
# File 'lib/pennmarc/helpers/relation.rb', line 88

def constituent_unit_show(record)
  values = record.fields('774').filter_map do |field|
    join_subfields(field, &subfield_in?(%w[i a s t]))
  end
  constituent_values = values + linked_alternate(record, '774', &subfield_in?(%w[i a s t]))
  constituent_values.uniq
end

.contained_in_show(record) ⇒ Array<String>

Get values for “Host Item” for this record. Values contained in this field should be sufficient to locate host item record.



16
17
18
19
20
# File 'lib/pennmarc/helpers/relation.rb', line 16

def contained_in_show(record)
  record.fields('773').map { |field|
    join_subfields(field, &subfield_not_in?(%w[6 7 8 w]))
  }.uniq
end

.contains_show(record, relator_map: Mappers.relator) ⇒ Array<String>

TODO:

is it okay to include 880 $4 here? Legacy includes untranslated $4, why?

Get “Contains” values from CONTAINS_FIELDS in the 7XX range. Must have indicator 2 value of 2 indicating an “Analytical Entry” meaning that the record is contained by the matching field. Map relator codes in sf 4. Ignore values in sf 0, 5, 6, and 8.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pennmarc/helpers/relation.rb', line 67

def contains_show(record, relator_map: Mappers.relator)
  fields = record.fields(CONTAINS_FIELDS)
  fields += record.fields('880').select { |f| subfield_value?(f, '6', /^(#{CONTAINS_FIELDS.join('|')})/) }
  fields.filter_map { |field|
    next unless field.indicator2 == '2'

    relator_term_sf = relator_term_subfield(field)

    sf_exclude = %w[0 4 5 6 8 i] << relator_term_sf

    values_with_title_prefix(field,
                             relator_term_sf: relator_term_sf,
                             relator_map: relator_map,
                             &subfield_not_in?(sf_exclude))
  }.uniq
end

.has_supplement_show(record) ⇒ Array

Get “Has Supplement” values from MARC 770. Ignore subfield values in 6 and 8.



100
101
102
# File 'lib/pennmarc/helpers/relation.rb', line 100

def has_supplement_show(record)
  datafield_and_linked_alternate(record, '770')
end

.publications_about_show(record) ⇒ Array

Get notes for “Publication About” from MARC 581.



32
33
34
# File 'lib/pennmarc/helpers/relation.rb', line 32

def publications_about_show(record)
  datafield_and_linked_alternate(record, '581')
end

Get notes for Related Collections from MARC 544.



25
26
27
# File 'lib/pennmarc/helpers/relation.rb', line 25

def related_collections_show(record)
  datafield_and_linked_alternate(record, '544')
end

Get related work from RELATED_WORK_FIELDS in the 7XX range. Require presence of sf t (title) and absence of an indicator2 value. Prefix returned values with sf i value. Also map relator codes found in sf 4. Ignore sf 0.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pennmarc/helpers/relation.rb', line 41

def related_work_show(record, relator_map: Mappers.relator)
  fields = record.fields(RELATED_WORK_FIELDS)
  fields += record.fields('880').select { |f| subfield_value?(f, '6', /^(#{RELATED_WORK_FIELDS.join('|')})/) }
  fields.filter_map { |field|
    next if field.indicator2.present?

    next unless subfield_defined?(field, 't')

    relator_term_sf = relator_term_subfield(field)

    sf_exclude = %w[0 4 6 8 i] << relator_term_sf

    values_with_title_prefix(field,
                             relator_term_sf: relator_term_sf,
                             relator_map: relator_map,
                             &subfield_not_in?(sf_exclude))
  }.uniq
end