mods_display 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/en.yml +1 -0
  3. data/lib/mods_display/fields/access_condition.rb +5 -5
  4. data/lib/mods_display/fields/cartographics.rb +6 -8
  5. data/lib/mods_display/fields/collection.rb +14 -14
  6. data/lib/mods_display/fields/contact.rb +7 -7
  7. data/lib/mods_display/fields/contents.rb +5 -1
  8. data/lib/mods_display/fields/date_other.rb +26 -0
  9. data/lib/mods_display/fields/description.rb +6 -3
  10. data/lib/mods_display/fields/edition.rb +3 -3
  11. data/lib/mods_display/fields/extent.rb +4 -4
  12. data/lib/mods_display/fields/field.rb +24 -19
  13. data/lib/mods_display/fields/form.rb +4 -4
  14. data/lib/mods_display/fields/frequency.rb +1 -1
  15. data/lib/mods_display/fields/genre.rb +5 -2
  16. data/lib/mods_display/fields/geo.rb +2 -2
  17. data/lib/mods_display/fields/identifier.rb +5 -2
  18. data/lib/mods_display/fields/imprint.rb +9 -9
  19. data/lib/mods_display/fields/issuance.rb +2 -2
  20. data/lib/mods_display/fields/language.rb +4 -4
  21. data/lib/mods_display/fields/location.rb +5 -5
  22. data/lib/mods_display/fields/name.rb +8 -7
  23. data/lib/mods_display/fields/nested_related_item.rb +13 -12
  24. data/lib/mods_display/fields/note.rb +10 -7
  25. data/lib/mods_display/fields/place.rb +5 -5
  26. data/lib/mods_display/fields/publisher.rb +2 -2
  27. data/lib/mods_display/fields/reference_title.rb +4 -4
  28. data/lib/mods_display/fields/related_item.rb +32 -34
  29. data/lib/mods_display/fields/resource_type.rb +7 -4
  30. data/lib/mods_display/fields/subject.rb +3 -3
  31. data/lib/mods_display/fields/title.rb +18 -18
  32. data/lib/mods_display/fields/values.rb +1 -0
  33. data/lib/mods_display/html.rb +1 -0
  34. data/lib/mods_display/version.rb +1 -1
  35. data/lib/mods_display.rb +1 -0
  36. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f82b0048ccbf7b94b1c15326c364b4133adf8c241145e98809e6e258cc15164
4
- data.tar.gz: '04349a0206e891f2ab84d23c7a182e5a5bd1b1e8227bb08deda07d23824b4511'
3
+ metadata.gz: 4152dce7ec61d92e04a5cddf9c5c152c414eeb725c05b975be1ec66eeadc2fa7
4
+ data.tar.gz: '087502061c3666fe0b4eec7c00a2a93e9532610cb4b35d7de6555a3dd7d2a8c8'
5
5
  SHA512:
6
- metadata.gz: 5e8ae4be6ab26e6e30fa74f0b71cc3a03c19ca33906770c5cf5c9819ccf11be9c92281e5b6443b8cb8905b0df285c93470a963d2c11ad2a37c1390166b77ee54
7
- data.tar.gz: 0e982271c57bdc0058dc5f005f2f0a9a84962e4ce01f1e0740bb3143e9332c2b8f4a398adc190520dd5509bdd8b85eb58bdeeaf8544910405759a703ff121198
6
+ metadata.gz: 1843e6a4f59a79c0f54f757e9c99820af6235681eea8a2c494bb40a6291db2f0408b6af26a6b8541bd91348cd1572c87329e510c12713df2afe9e72aea1a6baa
7
+ data.tar.gz: b4f433ae7fe636d51b92222cf64e8cbabdadcdc3aca05333165d9f0699957a59f94a4d254efad3e43e908f2b8991d12d7e70a652cdd10b15e639a7317b98d889
@@ -19,6 +19,7 @@ en:
19
19
  date_created: "Date created:"
20
20
  date_issued: "Publication date:"
21
21
  date_modified: "Date modified:"
22
+ date_other: "Other date:"
22
23
  date_sequential_designation: "Date/Sequential designation:"
23
24
  date_valid: "Date valid:"
24
25
  digital_origin: "Digital origin:"
@@ -51,10 +51,10 @@ module ModsDisplay
51
51
  }.freeze
52
52
 
53
53
  def fields
54
- return_fields = @values.map do |value|
54
+ return_fields = @stanford_mods_elements.map do |stanford_mods_element|
55
55
  ModsDisplay::Values.new(
56
- label: displayLabel(value) || access_label(value),
57
- values: [process_access_statement(value)],
56
+ label: displayLabel(stanford_mods_element) || access_label(stanford_mods_element),
57
+ values: [process_access_statement(stanford_mods_element)],
58
58
  field: self
59
59
  )
60
60
  end
@@ -85,7 +85,7 @@ module ModsDisplay
85
85
  def license_statement(element)
86
86
  element_text = element_text(element)
87
87
  legacy_matches = element_text.match(/^(?<code>.*) (?<type>.*):(?<description>.*)$/)
88
- return legacy_license_statement(element, legacy_matches) if legacy_matches
88
+ return legacy_license_statement(legacy_matches) if legacy_matches
89
89
 
90
90
  matches = element_text.match(/^This work is licensed under a (.+?)\.$/)
91
91
  return linked_licensed_statement(element, matches) if matches && element['xlink:href'].present?
@@ -97,7 +97,7 @@ module ModsDisplay
97
97
  "This work is licensed under a <a href='#{element['xlink:href']}'>#{matches[1]}</a>."
98
98
  end
99
99
 
100
- def legacy_license_statement(_element, matches)
100
+ def legacy_license_statement(matches)
101
101
  code = matches[:code].downcase
102
102
  type = matches[:type].downcase
103
103
  description = license_description(code, type) || matches[:description]
@@ -3,20 +3,18 @@
3
3
  module ModsDisplay
4
4
  class Cartographics < Field
5
5
  def fields
6
- return nil if @values.nil?
6
+ return nil if @stanford_mods_elements.nil?
7
7
 
8
8
  return_fields = []
9
- @values.each do |value|
10
- next unless value.respond_to?(:cartographics)
9
+ @stanford_mods_elements.each do |subject_element|
10
+ next unless subject_element.respond_to?(:cartographics)
11
11
 
12
- value.cartographics.each do |field|
12
+ subject_element.cartographics.each do |field|
13
13
  scale = field.scale.empty? ? 'Scale not given' : element_text(field.scale)
14
14
  projection = field.projection.empty? ? nil : element_text(field.projection)
15
15
  coordinates = field.coordinates.empty? ? nil : element_text(field.coordinates)
16
- post_scale = if [projection,
17
- coordinates].compact.length.positive?
18
- [projection, coordinates].compact.join(' ')
19
- end
16
+ post_scale = [projection, coordinates].compact.join(' ') if [projection, coordinates].compact.length.positive?
17
+
20
18
  return_fields << ModsDisplay::Values.new(
21
19
  label: displayLabel(field) || label || I18n.t('mods_display.map_data'),
22
20
  values: [[scale, post_scale].compact.join(' ; ')]
@@ -5,18 +5,18 @@ module ModsDisplay
5
5
  # Collection class to parse collection data out of Mods relatedItem fields
6
6
  ###
7
7
  class Collection < Field
8
- def collection_label(value)
9
- displayLabel(value) || I18n.t('mods_display.collection')
8
+ def collection_label(related_item_element)
9
+ displayLabel(related_item_element) || I18n.t('mods_display.collection')
10
10
  end
11
11
 
12
12
  def fields
13
13
  return_fields = []
14
- @values.each do |value|
15
- next unless related_item_is_a_collection?(value)
14
+ @stanford_mods_elements.each do |related_item_element|
15
+ next unless related_item_is_a_collection?(related_item_element)
16
16
 
17
17
  return_fields << ModsDisplay::Values.new(
18
- label: collection_label(value),
19
- values: [element_text(value.titleInfo)]
18
+ label: collection_label(related_item_element),
19
+ values: [element_text(related_item_element.titleInfo)]
20
20
  )
21
21
  end
22
22
  collapse_fields(return_fields)
@@ -24,17 +24,17 @@ module ModsDisplay
24
24
 
25
25
  private
26
26
 
27
- def related_item_is_a_collection?(value)
28
- value.respond_to?(:titleInfo) && resource_type_is_collection?(value)
27
+ def related_item_is_a_collection?(related_item_element)
28
+ related_item_element.respond_to?(:titleInfo) && resource_type_is_collection?(related_item_element)
29
29
  end
30
30
 
31
- def resource_type_is_collection?(value)
32
- return false unless value.respond_to?(:typeOfResource)
33
- return false unless value.typeOfResource.attributes.length.positive?
31
+ def resource_type_is_collection?(related_item_element)
32
+ return false unless related_item_element.respond_to?(:typeOfResource)
33
+ return false unless related_item_element.typeOfResource.attributes.length.positive?
34
34
 
35
- value.typeOfResource.attributes.length.positive? &&
36
- value.typeOfResource.attributes.first.key?('collection') &&
37
- value.typeOfResource.attributes.first['collection'].value == 'yes'
35
+ related_item_element.typeOfResource.attributes.length.positive? &&
36
+ related_item_element.typeOfResource.attributes.first.key?('collection') &&
37
+ related_item_element.typeOfResource.attributes.first['collection'].value == 'yes'
38
38
  end
39
39
  end
40
40
  end
@@ -3,10 +3,10 @@
3
3
  module ModsDisplay
4
4
  class Contact < Field
5
5
  def fields
6
- return_fields = contact_fields.map do |value|
6
+ return_fields = contact_elements.map do |contact_element|
7
7
  ModsDisplay::Values.new(
8
- label: displayLabel(value) || I18n.t('mods_display.contact'),
9
- values: [element_text(value)]
8
+ label: displayLabel(contact_element) || I18n.t('mods_display.contact'),
9
+ values: [element_text(contact_element)]
10
10
  )
11
11
  end
12
12
  collapse_fields(return_fields)
@@ -14,10 +14,10 @@ module ModsDisplay
14
14
 
15
15
  private
16
16
 
17
- def contact_fields
18
- @values.select do |value|
19
- value.attributes['type'].respond_to?(:value) &&
20
- value.attributes['type'].value.downcase == 'contact'
17
+ def contact_elements
18
+ @stanford_mods_elements.select do |note_element|
19
+ note_element.attributes['type'].respond_to?(:value) &&
20
+ note_element.attributes['type'].value.downcase == 'contact'
21
21
  end
22
22
  end
23
23
  end
@@ -4,7 +4,11 @@ module ModsDisplay
4
4
  class Contents < Field
5
5
  def to_html(view_context = ApplicationController.renderer)
6
6
  f = fields.map do |field|
7
- ModsDisplay::Values.new(label: field.label, values: [field.values.join("\n\n")], field: self)
7
+ ModsDisplay::Values.new(
8
+ label: field.label,
9
+ values: [field.values.join("\n\n")],
10
+ field: self
11
+ )
8
12
  end
9
13
 
10
14
  helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ModsDisplay
4
+ class DateOther < Field
5
+ def fields
6
+ date_fields(:dateOther)
7
+ end
8
+
9
+ private
10
+
11
+ # this is called from the Field.select_best_date method
12
+ # @param date [Stanford::Mods::Imprint::Date]
13
+ def qualified_value_with_type(date)
14
+ type = type_attribute_value(date)
15
+ type ? "#{date.qualified_value} (#{type})" : date.qualified_value
16
+ end
17
+
18
+ def type_attribute_value(date)
19
+ if date.is_a?(Stanford::Mods::Imprint::DateRange)
20
+ date.start.value.type || date.stop.value.type
21
+ else
22
+ date.value.type
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,8 +3,11 @@
3
3
  module ModsDisplay
4
4
  class Description < Field
5
5
  def fields
6
- return_fields = description_fields.map do |value|
7
- ModsDisplay::Values.new(label: description_label(value), values: [element_text(value)])
6
+ return_fields = description_fields.map do |element|
7
+ ModsDisplay::Values.new(
8
+ label: description_label(element),
9
+ values: [element_text(element)]
10
+ )
8
11
  end
9
12
  collapse_fields(return_fields)
10
13
  end
@@ -16,7 +19,7 @@ module ModsDisplay
16
19
  private
17
20
 
18
21
  def description_fields
19
- @values.children.select do |child|
22
+ @stanford_mods_elements.children.select do |child|
20
23
  labels.keys.include?(child.name.to_sym)
21
24
  end
22
25
  end
@@ -3,11 +3,11 @@
3
3
  module ModsDisplay
4
4
  class Edition < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- edition_value = Stanford::Mods::Imprint.new(value).edition_vals_str
6
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
7
+ edition_value = Stanford::Mods::Imprint.new(origin_info_element).edition_vals_str
8
8
  next unless edition_value.present?
9
9
 
10
- # remove trailing spaces (thanks MARC for catalog card formatting!)
10
+ # remove trailing spaces (thanks MARC, for catalog card formatting!)
11
11
  edition_value.gsub!(%r{ */$}, '')
12
12
 
13
13
  ModsDisplay::Values.new(
@@ -3,20 +3,20 @@
3
3
  module ModsDisplay
4
4
  class Extent < Field
5
5
  def fields
6
- return [] unless extent_fields.present?
6
+ return [] unless extent_elements.present?
7
7
 
8
8
  [
9
9
  ModsDisplay::Values.new(
10
10
  label: I18n.t('mods_display.extent'),
11
- values: extent_fields.map { |x| element_text(x) }
11
+ values: extent_elements.map { |x| element_text(x) }
12
12
  )
13
13
  ]
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def extent_fields
19
- @values.map(&:extent).flatten
18
+ def extent_elements
19
+ @stanford_mods_elements.map(&:extent).flatten
20
20
  end
21
21
  end
22
22
  end
@@ -1,16 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
+ # superclass for processing stanford-mods elements into ModsDisplay::Values retrieved by the fields method
5
+ # by consuming applications.
4
6
  class Field
5
- def initialize(values)
6
- @values = values
7
+ # @stanford_mods_elements is an array of Nokogiri::XML::Element-ish objects from stanford-mods
8
+ # per ModsDisplay::HTML::MODS_DISPLAY_FIELD_MAPPING
9
+ def initialize(stanford_mods_elements)
10
+ @stanford_mods_elements = stanford_mods_elements
7
11
  end
8
12
 
9
13
  def fields
10
- return_fields = @values.map do |value|
14
+ return_fields = @stanford_mods_elements.map do |stanford_mods_element|
11
15
  ModsDisplay::Values.new(
12
- label: displayLabel(value) || label,
13
- values: [element_text(value)],
16
+ label: displayLabel(stanford_mods_element) || label,
17
+ values: [element_text(stanford_mods_element)],
14
18
  field: self
15
19
  )
16
20
  end
@@ -18,9 +22,9 @@ module ModsDisplay
18
22
  end
19
23
 
20
24
  def label
21
- return nil if @values.nil?
25
+ return nil if @stanford_mods_elements.nil?
22
26
 
23
- displayLabel(@values.first)
27
+ displayLabel(@stanford_mods_elements.first)
24
28
  end
25
29
 
26
30
  def to_html(view_context = ApplicationController.renderer)
@@ -50,7 +54,10 @@ module ModsDisplay
50
54
  display_fields.slice_when { |before, after| before.label != after.label }.map do |group|
51
55
  next group.first if group.length == 1
52
56
 
53
- ModsDisplay::Values.new(label: group.first.label, values: group.map(&:values).flatten(1))
57
+ ModsDisplay::Values.new(
58
+ label: group.first.label,
59
+ values: group.map(&:values).flatten(1)
60
+ )
54
61
  end
55
62
  end
56
63
 
@@ -60,8 +67,8 @@ module ModsDisplay
60
67
 
61
68
  # used for originInfo date fields, e.g. DateCreated, DateIssued ...
62
69
  def date_fields(date_symbol)
63
- return_fields = @values.map do |value|
64
- date_values = Stanford::Mods::Imprint.new(value).dates([date_symbol])
70
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
71
+ date_values = Stanford::Mods::Imprint.new(origin_info_element).dates([date_symbol])
65
72
  next unless date_values.present?
66
73
 
67
74
  ModsDisplay::Values.new(
@@ -79,15 +86,10 @@ module ModsDisplay
79
86
  dates = dates.group_by(&:base_value).map do |_value, group|
80
87
  group.first if group.one?
81
88
 
82
- # if one of the duplicates wasn't encoded, use that one. see:
83
- # https://consul.stanford.edu/display/chimera/MODS+display+rules#MODSdisplayrules-3b.%3CoriginInfo%3E
84
- if group.reject(&:encoding).any?
85
- group.reject(&:encoding).first
86
-
87
- # otherwise just randomly pick the last in the group
88
- else
89
- group.last
90
- end
89
+ # if one of the duplicates wasn't encoded, use that one (see:
90
+ # https://consul.stanford.edu/display/chimera/MODS+display+rules#MODSdisplayrules-3b.%3CoriginInfo%3E),
91
+ # otherwise just randomly pick the last in the group
92
+ group.reject(&:encoding).first || group.last
91
93
  end
92
94
 
93
95
  # if any single dates are already part of a range, discard them
@@ -95,6 +97,9 @@ module ModsDisplay
95
97
  .map(&:base_values).flatten
96
98
  dates = dates.reject { |date| range_base_values.include?(date.base_value) }
97
99
 
100
+ # for DateOther field (but not for Imprint field), include the type attribute value in parens
101
+ return dates.map { |date| qualified_value_with_type(date) } if instance_of?(ModsDisplay::DateOther)
102
+
98
103
  # output formatted dates with qualifiers, CE/BCE, etc.
99
104
  dates.map(&:qualified_value)
100
105
  end
@@ -3,20 +3,20 @@
3
3
  module ModsDisplay
4
4
  class Form < Field
5
5
  def fields
6
- return [] unless form_fields.present?
6
+ return [] unless form_elements.present?
7
7
 
8
8
  [
9
9
  ModsDisplay::Values.new(
10
10
  label: I18n.t('mods_display.form'),
11
- values: form_fields.map { |x| element_text(x) }.uniq { |x| x.downcase.gsub(/\s/, '').gsub(/[[:punct:]]/, '') }
11
+ values: form_elements.map { |x| element_text(x) }.uniq { |x| x.downcase.gsub(/\s/, '').gsub(/[[:punct:]]/, '') }
12
12
  )
13
13
  ]
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def form_fields
19
- @values.map(&:form).flatten
18
+ def form_elements
19
+ @stanford_mods_elements.map(&:form).flatten
20
20
  end
21
21
  end
22
22
  end
@@ -3,7 +3,7 @@
3
3
  module ModsDisplay
4
4
  class Frequency < Field
5
5
  def fields
6
- return_fields = @values.map do |origin_info_element|
6
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
7
7
  frequency_value = origin_info_element.frequency&.text&.strip
8
8
  next unless frequency_value.present?
9
9
 
@@ -3,8 +3,11 @@
3
3
  module ModsDisplay
4
4
  class Genre < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || label, values: [element_text(value).capitalize].flatten)
6
+ return_fields = @stanford_mods_elements.map do |genre_element|
7
+ ModsDisplay::Values.new(
8
+ label: displayLabel(genre_element) || label,
9
+ values: [element_text(genre_element).capitalize].flatten
10
+ )
8
11
  end
9
12
  collapse_fields(return_fields)
10
13
  end
@@ -25,8 +25,8 @@ module ModsDisplay
25
25
  end
26
26
 
27
27
  def geo_extensions
28
- @geo_values ||= @values.select do |value|
29
- displayLabel(value) =~ /^geo:?$/
28
+ @geo_values ||= @stanford_mods_elements.select do |extension_element|
29
+ displayLabel(extension_element) =~ /^geo:?$/
30
30
  end
31
31
  end
32
32
  end
@@ -3,8 +3,11 @@
3
3
  module ModsDisplay
4
4
  class Identifier < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || identifier_label(value), values: [element_text(value)])
6
+ return_fields = @stanford_mods_elements.map do |identifier_element|
7
+ ModsDisplay::Values.new(
8
+ label: displayLabel(identifier_element) || identifier_label(identifier_element),
9
+ values: [element_text(identifier_element)]
10
+ )
8
11
  end
9
12
  collapse_fields(return_fields)
10
13
  end
@@ -9,28 +9,28 @@ module ModsDisplay
9
9
  end
10
10
 
11
11
  def origin_info_data
12
- @values.map do |value|
12
+ @stanford_mods_elements.map do |origin_info_element|
13
13
  return_fields = []
14
14
 
15
- edition = edition_element(value)
16
- place = place_element(value)
17
- publisher = publisher_element(value)
18
- parts = parts_element(value)
15
+ edition = edition_element(origin_info_element)
16
+ place = place_element(origin_info_element)
17
+ publisher = publisher_element(origin_info_element)
18
+ parts = parts_element(origin_info_element)
19
19
  place_pub = compact_and_join_with_delimiter([place, publisher], ' : ')
20
20
  edition_place = compact_and_join_with_delimiter([edition, place_pub], ' - ')
21
21
  joined_place_parts = compact_and_join_with_delimiter([edition_place, parts], ', ')
22
22
 
23
23
  unless joined_place_parts.empty?
24
24
  return_fields << ModsDisplay::Values.new(
25
- label: displayLabel(value) || I18n.t('mods_display.imprint'),
25
+ label: displayLabel(origin_info_element) || I18n.t('mods_display.imprint'),
26
26
  values: [joined_place_parts]
27
27
  )
28
28
  end
29
- return_fields.concat(date_values(value))
29
+ return_fields.concat(date_values(origin_info_element))
30
30
 
31
- other_pub_info(value).each do |pub_info|
31
+ other_pub_info(origin_info_element).each do |pub_info|
32
32
  return_fields << ModsDisplay::Values.new(
33
- label: displayLabel(value) || pub_info_labels[pub_info.name.to_sym],
33
+ label: displayLabel(origin_info_element) || pub_info_labels[pub_info.name.to_sym],
34
34
  values: [element_text(pub_info)]
35
35
  )
36
36
  end
@@ -3,12 +3,12 @@
3
3
  module ModsDisplay
4
4
  class Issuance < Field
5
5
  def fields
6
- return_fields = @values.map do |origin_info_element|
6
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
7
7
  issuance_value = origin_info_element.issuance&.text&.strip
8
8
  next unless issuance_value.present?
9
9
 
10
10
  ModsDisplay::Values.new(
11
- label: displayLabel(origin_info_element) || I18n.t('mods_display.issuance'),
11
+ label: I18n.t('mods_display.issuance'),
12
12
  values: [issuance_value],
13
13
  field: self
14
14
  )
@@ -3,14 +3,14 @@
3
3
  module ModsDisplay
4
4
  class Language < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- next unless value.respond_to?(:languageTerm)
6
+ return_fields = @stanford_mods_elements.map do |language_element|
7
+ next unless language_element.respond_to?(:languageTerm)
8
8
 
9
- value.languageTerm.map do |term|
9
+ language_element.languageTerm.map do |term|
10
10
  next unless term.attributes['type'].respond_to?(:value) && term.attributes['type'].value == 'code'
11
11
 
12
12
  ModsDisplay::Values.new(
13
- label: displayLabel(value) || displayLabel(term) || I18n.t('mods_display.language'),
13
+ label: displayLabel(language_element) || displayLabel(term) || I18n.t('mods_display.language'),
14
14
  values: [language_codes[element_text(term)]]
15
15
  )
16
16
  end.flatten.compact
@@ -4,20 +4,20 @@ module ModsDisplay
4
4
  class Location < Field
5
5
  def fields
6
6
  return_fields = []
7
- @values.each do |location|
8
- location.children.each do |child|
7
+ @stanford_mods_elements.each do |location_element|
8
+ location_element.children.each do |child|
9
9
  next unless location_field_keys.include?(child.name.to_sym)
10
10
 
11
11
  if child.name.to_sym == :url
12
- loc_label = displayLabel(location) || I18n.t('mods_display.location')
12
+ loc_label = displayLabel(location_element) || I18n.t('mods_display.location')
13
13
  value = "<a href='#{element_text(child)}'>#{(displayLabel(child) || element_text(child)).gsub(/:$/,
14
14
  '')}</a>"
15
15
  else
16
- loc_label = location_label(child) || displayLabel(location) || I18n.t('mods_display.location')
16
+ loc_label = location_label(child) || displayLabel(location_element) || I18n.t('mods_display.location')
17
17
  value = element_text(child)
18
18
  end
19
19
  return_fields << ModsDisplay::Values.new(
20
- label: loc_label || displayLabel(location) || I18n.t('mods_display.location'),
20
+ label: loc_label || displayLabel(location_element) || I18n.t('mods_display.location'),
21
21
  values: [value]
22
22
  )
23
23
  end
@@ -4,15 +4,16 @@ module ModsDisplay
4
4
  class Name < Field
5
5
  include ModsDisplay::RelatorCodes
6
6
 
7
- # this returns a hash:
8
- # { role1 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...], role2 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...] }
7
+ # returns a hash:
8
+ # { role1 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...],
9
+ # role2 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...] }
9
10
  def fields
10
- return_fields = @values.map do |value|
11
- name_parts = ModsDisplay::NameFormatter.format(value)
12
- person = name_parts ? ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: value.xpath('mods:nameIdentifier', mods: MODS_NS)) : nil
11
+ return_fields = @stanford_mods_elements.map do |plain_name_element|
12
+ name_parts = ModsDisplay::NameFormatter.format(plain_name_element)
13
+ person = name_parts ? ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: plain_name_element.xpath('mods:nameIdentifier', mods: MODS_NS)) : nil
13
14
  # The person may have multiple roles, so we have to divide them up into an array
14
- role_labels(value).collect do |role_label|
15
- ModsDisplay::Values.new(label: displayLabel(value) || role_label, values: [person]) if person
15
+ role_labels(plain_name_element).collect do |role_label|
16
+ ModsDisplay::Values.new(label: displayLabel(plain_name_element) || role_label, values: [person]) if person
16
17
  end
17
18
  end.flatten.compact
18
19
  collapse_roles(collapse_fields(return_fields))
@@ -15,14 +15,14 @@ module ModsDisplay
15
15
 
16
16
  def fields
17
17
  @fields ||= begin
18
- return_fields = RelatedItemValue.for_values(@values).map do |value|
19
- next if value.collection?
20
- next unless render_nested_related_item?(value)
18
+ return_fields = RelatedItemValue.for_values(@stanford_mods_elements).map do |related_item_element|
19
+ next if related_item_element.collection?
20
+ next unless render_nested_related_item?(related_item_element)
21
21
 
22
- related_item_text = @value_renderer.new(value).render
22
+ related_item_text = @value_renderer.new(related_item_element).render
23
23
 
24
24
  ModsDisplay::Values.new(
25
- label: related_item_label(value),
25
+ label: related_item_label(related_item_element),
26
26
  values: [related_item_text]
27
27
  )
28
28
  end.compact
@@ -30,9 +30,10 @@ module ModsDisplay
30
30
  end
31
31
  end
32
32
 
33
+ # this class provides html markup and is subclassed in purl application
33
34
  class ValueRenderer
34
- def initialize(value)
35
- @value = value
35
+ def initialize(related_item_element)
36
+ @related_item_element = related_item_element
36
37
  end
37
38
 
38
39
  def render
@@ -41,7 +42,7 @@ module ModsDisplay
41
42
 
42
43
  protected
43
44
 
44
- attr_reader :value
45
+ attr_reader :related_item_element
45
46
 
46
47
  def mods_display_html
47
48
  @mods_display_html ||= ModsDisplay::HTML.new(mods)
@@ -50,7 +51,7 @@ module ModsDisplay
50
51
  def mods
51
52
  @mods ||= ::Stanford::Mods::Record.new.tap do |r|
52
53
  # dup'ing the value adds the appropriate namespaces, but...
53
- munged_node = value.dup.tap do |x|
54
+ munged_node = related_item_element.dup.tap do |x|
54
55
  # ... the mods gem also expects the root of the document to have the root tag <mods>
55
56
  x.name = 'mods'
56
57
  end
@@ -68,9 +69,9 @@ module ModsDisplay
68
69
 
69
70
  private
70
71
 
71
- def related_item_label(item)
72
- return displayLabel(item) if displayLabel(item)
73
- return I18n.t('mods_display.constituent') if item.constituent?
72
+ def related_item_label(related_item_element)
73
+ return displayLabel(related_item_element) if displayLabel(related_item_element)
74
+ return I18n.t('mods_display.constituent') if related_item_element.constituent?
74
75
 
75
76
  I18n.t('mods_display.host')
76
77
  end
@@ -3,9 +3,12 @@
3
3
  module ModsDisplay
4
4
  class Note < Field
5
5
  def fields
6
- return_fields = note_fields.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)],
8
- field: self)
6
+ return_fields = note_fields.map do |note_element|
7
+ ModsDisplay::Values.new(
8
+ label: displayLabel(note_element) || note_label(note_element),
9
+ values: [element_text(note_element)],
10
+ field: self
11
+ )
9
12
  end
10
13
  collapse_fields(return_fields)
11
14
  end
@@ -17,10 +20,10 @@ module ModsDisplay
17
20
  end
18
21
 
19
22
  def note_fields
20
- @values.select do |value|
21
- !value.attributes['type'].respond_to?(:value) ||
22
- (value.attributes['type'].respond_to?(:value) &&
23
- value.attributes['type'].value.downcase != 'contact')
23
+ @stanford_mods_elements.select do |note_element|
24
+ !note_element.attributes['type'].respond_to?(:value) ||
25
+ (note_element.attributes['type'].respond_to?(:value) &&
26
+ note_element.attributes['type'].value.downcase != 'contact')
24
27
  end
25
28
  end
26
29
 
@@ -5,8 +5,8 @@ module ModsDisplay
5
5
  include ModsDisplay::CountryCodes
6
6
 
7
7
  def fields
8
- return_fields = @values.map do |value|
9
- place_value = place_element(value)
8
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
9
+ place_value = place_element(origin_info_element)
10
10
  next unless place_value.present?
11
11
 
12
12
  ModsDisplay::Values.new(
@@ -21,10 +21,10 @@ module ModsDisplay
21
21
  private
22
22
 
23
23
  # not an exact duplicate of the method in Imprint, particularly trailing punctuation code
24
- def place_element(value)
25
- return if value.place.text.strip.empty?
24
+ def place_element(origin_info_element)
25
+ return if origin_info_element.place.text.strip.empty?
26
26
 
27
- places = ModsDisplay::Imprint.new(value).place_terms(value).filter_map { |p| p.text unless p.text.strip.empty? }
27
+ places = ModsDisplay::Imprint.new(origin_info_element).place_terms(origin_info_element).filter_map { |p| p.text unless p.text.strip.empty? }
28
28
  compact_and_remove_trailing_delimiter(places, ':').join
29
29
  end
30
30
 
@@ -3,8 +3,8 @@
3
3
  module ModsDisplay
4
4
  class Publisher < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- publisher_value = Stanford::Mods::Imprint.new(value).publisher_vals_str
6
+ return_fields = @stanford_mods_elements.map do |origin_info_element|
7
+ publisher_value = Stanford::Mods::Imprint.new(origin_info_element).publisher_vals_str
8
8
  next unless publisher_value.present?
9
9
 
10
10
  publisher_value.gsub!(/ *,$/, '')
@@ -4,16 +4,16 @@ module ModsDisplay
4
4
  class ReferenceTitle < Field
5
5
  def fields
6
6
  # Reference title is a composite field that includes parts from elsewhere in the record.
7
- return [] unless @values.present?
7
+ return [] unless @stanford_mods_elements.present?
8
8
 
9
- return_fields = [ModsDisplay::Values.new(label: displayLabel(@values.first) || label, values: [title_value].compact)]
9
+ return_fields = [ModsDisplay::Values.new(label: displayLabel(@stanford_mods_elements.first) || label, values: [title_value].compact)]
10
10
  collapse_fields(return_fields)
11
11
  end
12
12
 
13
13
  private
14
14
 
15
15
  def root
16
- @root ||= @values.first.document.root
16
+ @root ||= @stanford_mods_elements.first.document.root
17
17
  end
18
18
 
19
19
  def displayLabel(element)
@@ -21,7 +21,7 @@ module ModsDisplay
21
21
  end
22
22
 
23
23
  def title_value
24
- [@values,
24
+ [@stanford_mods_elements,
25
25
  root.xpath('mods:originInfo/mods:dateOther', mods: MODS_NS),
26
26
  root.xpath('mods:part/mods:detail/mods:number', mods: MODS_NS),
27
27
  root.xpath('mods:note', mods: MODS_NS)].flatten.compact.map!(&:text).map!(&:strip).join(' ').presence
@@ -10,33 +10,37 @@ module ModsDisplay
10
10
  end
11
11
 
12
12
  def fields
13
- return_fields = RelatedItemValue.for_values(@values).map do |value|
14
- next if value.collection?
15
- next if render_nested_related_item?(value)
16
-
17
- text = @value_renderer.new(value).render
13
+ return_fields = RelatedItemValue.for_values(@stanford_mods_elements).map do |related_item_element|
14
+ next if related_item_element.collection?
15
+ next if render_nested_related_item?(related_item_element)
18
16
 
17
+ text = @value_renderer.new(related_item_element).render
19
18
  next if text.nil? || text.empty?
20
19
 
21
- ModsDisplay::Values.new(label: related_item_label(value), values: [text])
20
+ ModsDisplay::Values.new(
21
+ label: related_item_label(related_item_element),
22
+ values: [text]
23
+ )
22
24
  end.compact
23
25
  collapse_fields(return_fields)
24
26
  end
25
27
 
28
+ # this class provides html markup and is mimicking the same class
29
+ # in NestedRelatedItem (which is subclassed in purl application)
26
30
  class ValueRenderer
27
- def initialize(value)
28
- @value = value
31
+ def initialize(related_item_element)
32
+ @related_item_element = related_item_element
29
33
  end
30
34
 
31
35
  def render
32
- if value.location?
33
- element_text(value.location_nodeset)
34
- elsif value.reference?
35
- reference_title(value)
36
- elsif value.titleInfo_nodeset.any?
37
- title = element_text(value.titleInfo_nodeset)
36
+ if related_item_element.location?
37
+ element_text(related_item_element.location_nodeset)
38
+ elsif related_item_element.reference?
39
+ reference_title(related_item_element)
40
+ elsif related_item_element.titleInfo_nodeset.any?
41
+ title = element_text(related_item_element.titleInfo_nodeset)
38
42
  location = nil
39
- location = element_text(value.location_url_nodeset) if value.location_url_nodeset.length.positive?
43
+ location = element_text(related_item_element.location_url_nodeset) if related_item_element.location_url_nodeset.length.positive?
40
44
 
41
45
  return if title.empty?
42
46
 
@@ -45,8 +49,8 @@ module ModsDisplay
45
49
  else
46
50
  title
47
51
  end
48
- elsif value.note_nodeset.any?
49
- citation = value.note_nodeset.find { |note| note['type'] == 'preferred citation' }
52
+ elsif related_item_element.note_nodeset.any?
53
+ citation = related_item_element.note_nodeset.find { |note| note['type'] == 'preferred citation' }
50
54
 
51
55
  element_text(citation) if citation
52
56
  end
@@ -54,36 +58,30 @@ module ModsDisplay
54
58
 
55
59
  protected
56
60
 
57
- attr_reader :value
61
+ attr_reader :related_item_element
58
62
 
59
63
  def element_text(element)
60
64
  element.xpath('.//text()').to_html.strip
61
65
  end
62
66
 
63
- def reference_title(item)
64
- [item.titleInfo_nodeset,
65
- item.originInfo.dateOther,
66
- item.part.detail.number,
67
- item.note_nodeset].flatten.compact.map!(&:text).map!(&:strip).join(' ')
67
+ def reference_title(related_item_element)
68
+ [related_item_element.titleInfo_nodeset,
69
+ related_item_element.originInfo.dateOther,
70
+ related_item_element.part.detail.number,
71
+ related_item_element.note_nodeset].flatten.compact.map!(&:text).map!(&:strip).join(' ')
68
72
  end
69
73
  end
70
74
 
71
75
  private
72
76
 
73
- attr_reader :value_renderer
74
-
75
- def delimiter
76
- '<br />'.html_safe
77
- end
78
-
79
- def related_item_label(item)
80
- if displayLabel(item)
81
- displayLabel(item)
77
+ def related_item_label(related_item_element)
78
+ if displayLabel(related_item_element)
79
+ displayLabel(related_item_element)
82
80
  else
83
81
  case
84
- when item.location?
82
+ when related_item_element.location?
85
83
  return I18n.t('mods_display.location')
86
- when item.reference?
84
+ when related_item_element.reference?
87
85
  return I18n.t('mods_display.referenced_by')
88
86
  end
89
87
  I18n.t('mods_display.related_item')
@@ -3,16 +3,19 @@
3
3
  module ModsDisplay
4
4
  class ResourceType < Field
5
5
  def fields
6
- return_fields = @values.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || label, values: [element_text(value)])
6
+ return_fields = @stanford_mods_elements.map do |type_of_resource_element|
7
+ ModsDisplay::Values.new(
8
+ label: displayLabel(type_of_resource_element) || label,
9
+ values: [element_text(type_of_resource_element)]
10
+ )
8
11
  end
9
12
  collapse_fields(return_fields)
10
13
  end
11
14
 
12
15
  private
13
16
 
14
- def displayLabel(element)
15
- super(element) || I18n.t('mods_display.type_of_resource')
17
+ def displayLabel(type_of_resource_element)
18
+ super(type_of_resource_element) || I18n.t('mods_display.type_of_resource')
16
19
  end
17
20
  end
18
21
  end
@@ -4,11 +4,11 @@ module ModsDisplay
4
4
  class Subject < Field
5
5
  def fields
6
6
  return_fields = []
7
- @values.each do |value|
7
+ @stanford_mods_elements.each do |subject_element|
8
8
  return_values = []
9
- label = displayLabel(value) || I18n.t('mods_display.subject')
9
+ label = displayLabel(subject_element) || I18n.t('mods_display.subject')
10
10
  return_text = []
11
- selected_subjects(value).each do |child|
11
+ selected_subjects(subject_element).each do |child|
12
12
  if respond_to?(:"process_#{child.name}")
13
13
  method_send = send(:"process_#{child.name}", child)
14
14
  return_text << method_send unless method_send.to_s.empty?
@@ -8,10 +8,10 @@ module ModsDisplay
8
8
  end
9
9
 
10
10
  def fields
11
- return_values = sorted_values.map do |value|
11
+ return_values = sorted_title_info_elements.map do |title_info_element|
12
12
  ModsDisplay::Values.new(
13
- label: displayLabel(value) || title_label(value),
14
- values: [assemble_title(value)]
13
+ label: displayLabel(title_info_element) || title_label(title_info_element),
14
+ values: [assemble_title(title_info_element)]
15
15
  )
16
16
  end
17
17
  collapse_fields(return_values)
@@ -20,50 +20,50 @@ module ModsDisplay
20
20
  private
21
21
 
22
22
  # If there is a node with usage="primary", then it should come first.
23
- def sorted_values
24
- Array(@values).sort_by { |node| node['usage'] == 'primary' ? 0 : 1 }
23
+ def sorted_title_info_elements
24
+ Array(@stanford_mods_elements).sort_by { |title_info_element| title_info_element['usage'] == 'primary' ? 0 : 1 }
25
25
  end
26
26
 
27
27
  def delimiter
28
28
  '<br />'.html_safe
29
29
  end
30
30
 
31
- def assemble_title(element)
31
+ def assemble_title(title_info_element)
32
32
  title = ''
33
33
  previous_element = nil
34
34
 
35
- element.children.select { |value| title_parts.include? value.name }.each do |value|
36
- str = value.text.strip
37
- next if str.empty?
35
+ title_info_element.children.select { |child| title_parts.include? child.name }.each do |child|
36
+ text = child.text.strip
37
+ next if text.empty?
38
38
 
39
- delimiter = title_delimiter(title, previous_element, value)
39
+ delimiter = title_delimiter(title, previous_element, child)
40
40
 
41
41
  title += delimiter if delimiter
42
- title += str
42
+ title += text
43
43
 
44
- previous_element = value
44
+ previous_element = child
45
45
  end
46
46
 
47
- full_title = if element['type'] == 'uniform' && element['nameTitleGroup'].present?
48
- [uniform_title_name_part(element), title].compact.join('. ')
47
+ full_title = if title_info_element['type'] == 'uniform' && title_info_element['nameTitleGroup'].present?
48
+ [uniform_title_name_part(title_info_element), title].compact.join('. ')
49
49
  else
50
50
  title
51
51
  end
52
52
  linked_title(full_title)
53
53
  end
54
54
 
55
- def title_delimiter(title, previous_element, value)
55
+ def title_delimiter(title, previous_element, child)
56
56
  if title.empty? || title.end_with?(' ')
57
57
  nil
58
58
  elsif previous_element&.name == 'nonSort' && title.end_with?('-', '\'')
59
59
  nil
60
60
  elsif title.end_with?('.', ',', ':', ';')
61
61
  ' '
62
- elsif value.name == 'subTitle'
62
+ elsif child.name == 'subTitle'
63
63
  ' : '
64
- elsif value.name == 'partName' && previous_element.name == 'partNumber'
64
+ elsif child.name == 'partName' && previous_element.name == 'partNumber'
65
65
  ', '
66
- elsif value.name == 'partNumber' || value.name == 'partName'
66
+ elsif child.name == 'partNumber' || child.name == 'partName'
67
67
  '. '
68
68
  else
69
69
  ' '
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
+ # This class has what is needed by view code in downstream applications
4
5
  class Values
5
6
  attr_accessor :label, :values, :field
6
7
 
@@ -17,6 +17,7 @@ module ModsDisplay
17
17
  dateCreated: :origin_info,
18
18
  dateIssued: :origin_info,
19
19
  dateModified: :origin_info,
20
+ dateOther: :origin_info,
20
21
  dateValid: :origin_info,
21
22
  edition: :origin_info,
22
23
  frequency: :origin_info,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
- VERSION = '1.5.0'
4
+ VERSION = '1.6.0'
5
5
  end
data/lib/mods_display.rb CHANGED
@@ -19,6 +19,7 @@ require 'mods_display/fields/date_created'
19
19
  require 'mods_display/fields/date_captured'
20
20
  require 'mods_display/fields/date_issued'
21
21
  require 'mods_display/fields/date_modified'
22
+ require 'mods_display/fields/date_other'
22
23
  require 'mods_display/fields/date_valid'
23
24
  require 'mods_display/fields/description'
24
25
  require 'mods_display/fields/edition'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Keck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-04 00:00:00.000000000 Z
11
+ date: 2023-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods
@@ -211,6 +211,7 @@ files:
211
211
  - lib/mods_display/fields/date_created.rb
212
212
  - lib/mods_display/fields/date_issued.rb
213
213
  - lib/mods_display/fields/date_modified.rb
214
+ - lib/mods_display/fields/date_other.rb
214
215
  - lib/mods_display/fields/date_valid.rb
215
216
  - lib/mods_display/fields/description.rb
216
217
  - lib/mods_display/fields/edition.rb
@@ -261,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
262
  - !ruby/object:Gem::Version
262
263
  version: '0'
263
264
  requirements: []
264
- rubygems_version: 3.3.7
265
+ rubygems_version: 3.4.13
265
266
  signing_key:
266
267
  specification_version: 4
267
268
  summary: The MODS Display gem allows implementers to configure a customized display