Class: PennMARC::Production

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

Overview

Extracts data related to a resource’s production, distribution, manufacture, and publication.

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

.distribution_show(record) ⇒ Array<String>

Retrieve distribution values for display from 264 field.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


33
34
35
# File 'lib/pennmarc/helpers/production.rb', line 33

def distribution_show(record)
  get_264_or_880_fields(record, '2').uniq
end

.manufacture_show(record) ⇒ Array<String>

Retrieve manufacture values for display from 264 field.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


40
41
42
# File 'lib/pennmarc/helpers/production.rb', line 40

def manufacture_show(record)
  get_264_or_880_fields(record, '3').uniq
end

.place_of_publication_search(record) ⇒ Array<String>

Retrieves place of publication values for searching. Includes 752 as well as sf a from 260 and 264 with an indicator2 of 1.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/pennmarc/helpers/production.rb', line 168

def place_of_publication_search(record)
  values = record.fields('260').filter_map do |field|
    join_subfields(field, &subfield_in?(['a']))
  end
  values += record.fields('264').filter_map do |field|
    next unless field.indicator2 == '1'

    join_subfields(field, &subfield_in?(['a']))
  end
  values + record.fields('752').filter_map { |field|
    join_subfields(field, &subfield_in?(%w[a b c d f g h]))
  }.uniq
end

.place_of_publication_show(record) ⇒ Array<String>

Note:

legacy version returns array of hash objects including data for display link

Retrieve place of publication for display from 752 field and its linked alternate.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


152
153
154
155
156
157
158
159
160
# File 'lib/pennmarc/helpers/production.rb', line 152

def place_of_publication_show(record)
  record.fields(%w[752 880]).filter_map { |field|
    next if field.tag == '880' && no_subfield_value_matches?(field, '6', /^752/)

    place = join_subfields(field, &subfield_not_in?(%w[6 8 e w]))
    place_extra = join_subfields(field, &subfield_in?(%w[e w]))
    "#{place} #{place_extra}"
  }.uniq
end

.publication_citation_show(record, with_year: true) ⇒ Array<String>

Retrieve publication values for citation 245, 260-262 and their linked alternates, and 264 and its linked alternate.

Parameters:

  • record (MARC::Record)
  • with_year (Boolean) (defaults to: true)

    return results with publication year if true

Returns:

  • (Array<String>)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/pennmarc/helpers/production.rb', line 115

def publication_citation_show(record, with_year: true)
  values = record.fields('245').first(1).flat_map { |field| subfield_values(field, 'f') }

  subfields = with_year ? %w[6 8] : %w[6 8 c]
  values += record.fields(%w[260 261 262]).first(1).map do |field|
    join_subfields(field, &subfield_not_in?(subfields))
  end

  subfields = with_year ? %w[a b c] : %w[a b]
  values += record.fields('264').filter_map do |field|
    next unless field.indicator2 == '1'

    join_subfields(field, &subfield_in?(subfields))
  end

  values.compact_blank.uniq
end

.publication_ris_place_of_pub(record) ⇒ Array<String>

Returns the place of publication for RIS

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


136
137
138
# File 'lib/pennmarc/helpers/production.rb', line 136

def publication_ris_place_of_pub(record)
  get_publication_ris_values(record, 'a')
end

.publication_ris_publisher(record) ⇒ Array<String>

Returns the publisher for RIS

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


143
144
145
# File 'lib/pennmarc/helpers/production.rb', line 143

def publication_ris_publisher(record)
  get_publication_ris_values(record, 'b')
end

.publication_show(record) ⇒ Array<String>

Retrieve publication values for display from fields 245, 260-262 and their linked alternates, and 264 and its linked alternate.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pennmarc/helpers/production.rb', line 88

def publication_show(record)
  values = record.fields('245').first(1).flat_map { |field| subfield_values(field, 'f') }

  values += record.fields(%w[260 261 262]).first(1).map do |field|
    join_subfields(field, &subfield_not_in?(%w[6 8]))
  end

  values += record.fields('880').filter_map { |field| field if subfield_value?(field, '6', /^(260|261|262)/) }
                  .first(1).map { |field| join_subfields(field, &subfield_not_in?(%w[6 8])) }

  values += record.fields('880').filter_map do |field|
    next unless subfield_value?(field, '6', /^245/)

    join_subfields(field, &subfield_in?(['f']))
  end

  values += get_264_or_880_fields(record, '1')
  values.compact_blank.uniq
end

.publication_values(record) ⇒ Array<String>

Retrieve publication values. Return publication values from 264 field only if none found 260-262 fields.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pennmarc/helpers/production.rb', line 49

def publication_values(record)
  # first get inclusive dates
  values = record.fields('245').first(1).flat_map { |field| subfield_values(field, 'f') }
  added_2xx = record.fields(%w[260 261 262])
                    .first(1)
                    .map do |field|
    join_subfields(field, &subfield_not_in?(['6'])).squish
  end

  if added_2xx.present?
    values += added_2xx
  else
    fields264 = record.fields('264')

    pub_place_name = fields264
                     .find(-> { [] }) { |field| field.indicator2 == '1' }
                     .filter_map { |sf| sf.value if sf.code.in?(%w[a b]) }

    pub_date = fields264
               .find(-> { [] }) { |field| field.indicator2 == '1' }
               .filter_map { |sf| sf.value if sf.code.in?(['c']) }

    copyright_date = fields264
                     .find(-> { [] }) { |field| field.indicator2 == '4' }
                     .filter_map { |sf| "#{pub_date.present? ? ', ' : ''}#{sf.value}" if sf.code.in?(['c']) }

    joined264 = Array.wrap((pub_place_name + pub_date + copyright_date).join(' '))

    values += joined264
  end
  values.filter_map { |value| value&.strip }.uniq
end

.search(record) ⇒ Array<String>

Retrieve production values for searching. Includes only 260 and 264.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


19
20
21
22
23
24
25
26
27
28
# File 'lib/pennmarc/helpers/production.rb', line 19

def search(record)
  values = record.fields('260').filter_map do |field|
    join_subfields(field, &subfield_in?(['b']))
  end
  values + record.fields('264').filter_map { |field|
    next unless field.indicator2 == '1'

    join_subfields(field, &subfield_in?(['b']))
  }.uniq
end

.show(record) ⇒ Array<String>

Retrieve production values for display from 264 field.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


10
11
12
# File 'lib/pennmarc/helpers/production.rb', line 10

def show(record)
  get_264_or_880_fields(record, '0').uniq
end