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

CHRONOLOGY_PREFIX =
'CHR'
%w[700 710 711 730].freeze
CONTAINS_FIELDS =
%w[700 710 711 730 740].freeze

Class Method Summary collapse

Methods included from Util

#datafield_and_linked_alternate, #join_and_squish, #join_subfields, #linked_alternate, #linked_alternate_not_6_or_8, #prefixed_subject_and_alternate, #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, #valid_subject_genre_source_code?

Class Method Details

.chronology_show(record) ⇒ Array

TODO:

why do we stuff chronology data in a 650 field?

Get “chronology” information from specially-prefixed 650 (subject) fields

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)

    array of chronology values



28
29
30
# File 'lib/pennmarc/helpers/relation.rb', line 28

def chronology_show(record)
  prefixed_subject_and_alternate(record, CHRONOLOGY_PREFIX)
end

.constituent_unit_show(record) ⇒ Array

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

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)


95
96
97
98
99
100
# File 'lib/pennmarc/helpers/relation.rb', line 95

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

.contained_in_show(record) ⇒ Array

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

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)

    contained in values for display



18
19
20
21
22
# File 'lib/pennmarc/helpers/relation.rb', line 18

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

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

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.

Parameters:

  • record (MARC::Record)
  • relator_map (Hash) (defaults to: Mappers.relator)

Returns:

  • (Array)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pennmarc/helpers/relation.rb', line 76

def contains_show(record, relator_map: Mappers.relator)
  acc = record.fields(CONTAINS_FIELDS).filter_map do |field|
    next unless field.indicator2 == '2'

    values_with_title_prefix(field, sf_exclude: %w[0 4 5 6 8 i], relator_map: relator_map)
  end
  acc + record.fields('880').filter_map do |field|
    next unless field.indicator2 == '2'

    next unless subfield_value?(field, '6', /^(#{CONTAINS_FIELDS.join('|')})/)

    values_with_title_prefix(field, sf_include: %w[0 5 6 8 i])
  end
end

.has_supplement_show(record) ⇒ Array

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

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)


106
107
108
# File 'lib/pennmarc/helpers/relation.rb', line 106

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.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)


42
43
44
# File 'lib/pennmarc/helpers/relation.rb', line 42

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

Get notes for Related Collections from MARC 544.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)


35
36
37
# File 'lib/pennmarc/helpers/relation.rb', line 35

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.

Parameters:

  • record (MARC::Record)
  • relator_map (Hash) (defaults to: Mappers.relator)

Returns:

  • (Array)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pennmarc/helpers/relation.rb', line 51

def related_work_show(record, relator_map: Mappers.relator)
  values = record.fields(RELATED_WORK_FIELDS).filter_map do |field|
    next if field.indicator2.present?

    next unless subfield_defined?(field, 't')

    values_with_title_prefix(field, sf_exclude: %w[0 4 6 8 i], relator_map: relator_map)
  end
  values + record.fields('880').filter_map do |field|
    next if field.indicator2.present?

    next unless subfield_value?(field, '6', /^(#{RELATED_WORK_FIELDS.join('|')})/)

    next unless subfield_defined?(field, 't')

    values_with_title_prefix(field, sf_exclude: %w[0 4 6 8 i], relator_map: relator_map)
  end
end