mods_display 1.3.5 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mods_display/fields/name.rb +4 -63
- data/lib/mods_display/name_formatter.rb +72 -0
- data/lib/mods_display/version.rb +1 -1
- data/lib/mods_display.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd385f9d4aea6c14524378831877c327c6fdfd2664356e148b457af9c26a5623
|
4
|
+
data.tar.gz: b66857f71c766dc6edb03b8783d1d63486e94c63c8e9a71a0474f6b5a11d44cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b4760e8eee0c1eef22badaf5087b4095c4c88766c3b128bbaa1e841e2b1aa34294ced0be7199875b6aa57cdf1b3385dd5c11d624f4ce818afcc7fa4f1da25ab
|
7
|
+
data.tar.gz: 93c93c4249b55816c9716b1c632d0b4c5b5a2874365e33139fbbf6cd9421f01d3aa9800d347c72ae7837bcf98ef763650e8151a3cab547cecb287a72ff7a9ace
|
@@ -7,12 +7,9 @@ module ModsDisplay
|
|
7
7
|
# this returns a hash:
|
8
8
|
# { role1 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...], role2 label => [ ModsDisplay:Name:Person, ModsDisplay:Name:Person, ...] }
|
9
9
|
def fields
|
10
|
-
return_fields =
|
11
|
-
|
12
|
-
|
13
|
-
elsif !(name_parts = name_parts(value)).empty?
|
14
|
-
ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: value.nameIdentifier_nodeset)
|
15
|
-
end
|
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
|
16
13
|
# The person may have multiple roles, so we have to divide them up into an array
|
17
14
|
role_labels(value).collect do |role_label|
|
18
15
|
ModsDisplay::Values.new(label: displayLabel(value) || role_label, values: [person]) if person
|
@@ -51,7 +48,7 @@ module ModsDisplay
|
|
51
48
|
default_label = I18n.t('mods_display.associated_with')
|
52
49
|
return [default_label] unless element.xpath('mods:role/mods:roleTerm', mods: MODS_NS).present?
|
53
50
|
|
54
|
-
element.
|
51
|
+
element.xpath('mods:role', mods: MODS_NS).collect do |role|
|
55
52
|
codes, text = role.xpath('mods:roleTerm', mods: MODS_NS).partition { |term| term['type'] == 'code' }
|
56
53
|
|
57
54
|
# prefer mappable role term codes
|
@@ -69,40 +66,6 @@ module ModsDisplay
|
|
69
66
|
element_text(element).capitalize.sub(/[.,:;]+$/, '')
|
70
67
|
end
|
71
68
|
|
72
|
-
def name_parts(element)
|
73
|
-
output = [unqualified_name_parts(element),
|
74
|
-
qualified_name_parts(element, 'family'),
|
75
|
-
qualified_name_parts(element, 'given')].flatten.compact.join(', ')
|
76
|
-
terms = qualified_name_parts(element, 'termsOfAddress')
|
77
|
-
unless terms.empty?
|
78
|
-
term_delimiter = ', '
|
79
|
-
term_delimiter = ' ' if name_part_begins_with_roman_numeral?(terms.first)
|
80
|
-
output = [output, terms.join(', ')].flatten.compact.join(term_delimiter)
|
81
|
-
end
|
82
|
-
dates = qualified_name_parts(element, 'date')
|
83
|
-
output = [output, dates].flatten.compact.join(', ') unless dates.empty?
|
84
|
-
output
|
85
|
-
end
|
86
|
-
|
87
|
-
def unqualified_name_parts(element)
|
88
|
-
element.namePart_nodeset.map do |part|
|
89
|
-
element_text(part) unless part.attributes['type']
|
90
|
-
end.compact
|
91
|
-
end
|
92
|
-
|
93
|
-
def qualified_name_parts(element, type)
|
94
|
-
element.namePart_nodeset.map do |part|
|
95
|
-
element_text(part) if part.get_attribute('type') == type
|
96
|
-
end.compact
|
97
|
-
end
|
98
|
-
|
99
|
-
def name_part_begins_with_roman_numeral?(part)
|
100
|
-
first_part = part.split(/\s|,/).first.strip
|
101
|
-
first_part.chars.all? do |char|
|
102
|
-
%w[I X C L V].include? char
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
69
|
# Consolidate all names under label headings
|
107
70
|
def consolidate_under_labels(fields)
|
108
71
|
results = {}
|
@@ -162,27 +125,5 @@ module ModsDisplay
|
|
162
125
|
orcid.first&.text
|
163
126
|
end
|
164
127
|
end
|
165
|
-
|
166
|
-
class NameValue < SimpleDelegator
|
167
|
-
def self.for_values(values)
|
168
|
-
values.map { |value| new(value) }
|
169
|
-
end
|
170
|
-
|
171
|
-
def nameIdentifier_nodeset
|
172
|
-
@nameIdentifier_nodeset ||= xpath('mods:nameIdentifier', mods: MODS_NS)
|
173
|
-
end
|
174
|
-
|
175
|
-
def displayForm_nodeset
|
176
|
-
@displayForm_nodeset ||= xpath('mods:displayForm', mods: MODS_NS)
|
177
|
-
end
|
178
|
-
|
179
|
-
def namePart_nodeset
|
180
|
-
@namePart_nodeset ||= xpath('mods:namePart', mods: MODS_NS)
|
181
|
-
end
|
182
|
-
|
183
|
-
def role_nodeset
|
184
|
-
@role_nodeset ||= xpath('mods:role', mods: MODS_NS)
|
185
|
-
end
|
186
|
-
end
|
187
128
|
end
|
188
129
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ModsDisplay
|
4
|
+
class NameFormatter
|
5
|
+
def self.format(element)
|
6
|
+
new(element).format
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(element)
|
10
|
+
@element = element
|
11
|
+
end
|
12
|
+
|
13
|
+
def format
|
14
|
+
return element_text(display_form_nodeset) if display_form_nodeset.present?
|
15
|
+
return name_parts if name_parts.present?
|
16
|
+
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :element
|
23
|
+
|
24
|
+
def name_parts
|
25
|
+
@name_parts ||= begin
|
26
|
+
output = [unqualified_name_parts(name_part_nodeset),
|
27
|
+
qualified_name_parts(name_part_nodeset, 'family'),
|
28
|
+
qualified_name_parts(name_part_nodeset, 'given')].flatten.compact.join(', ')
|
29
|
+
terms = qualified_name_parts(name_part_nodeset, 'termsOfAddress')
|
30
|
+
unless terms.empty?
|
31
|
+
term_delimiter = ', '
|
32
|
+
term_delimiter = ' ' if name_part_begins_with_roman_numeral?(terms.first)
|
33
|
+
output = [output, terms.join(', ')].flatten.compact.join(term_delimiter)
|
34
|
+
end
|
35
|
+
dates = qualified_name_parts(name_part_nodeset, 'date')
|
36
|
+
output = [output, dates].flatten.compact.join(', ') unless dates.empty?
|
37
|
+
output
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def unqualified_name_parts(name_part_nodeset)
|
42
|
+
name_part_nodeset.map do |part|
|
43
|
+
element_text(part) unless part.attributes['type']
|
44
|
+
end.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def qualified_name_parts(name_part_nodeset, type)
|
48
|
+
name_part_nodeset.map do |part|
|
49
|
+
element_text(part) if part.get_attribute('type') == type
|
50
|
+
end.compact
|
51
|
+
end
|
52
|
+
|
53
|
+
def name_part_begins_with_roman_numeral?(part)
|
54
|
+
first_part = part.split(/\s|,/).first.strip
|
55
|
+
first_part.chars.all? do |char|
|
56
|
+
%w[I X C L V].include? char
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def element_text(element)
|
61
|
+
element.text.strip
|
62
|
+
end
|
63
|
+
|
64
|
+
def name_part_nodeset
|
65
|
+
@name_part_nodeset ||= element.xpath('mods:namePart', mods: MODS_NS)
|
66
|
+
end
|
67
|
+
|
68
|
+
def display_form_nodeset
|
69
|
+
@display_form_nodeset ||= element.xpath('mods:displayForm', mods: MODS_NS)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/mods_display/version.rb
CHANGED
data/lib/mods_display.rb
CHANGED
@@ -5,6 +5,7 @@ require 'mods_display/html'
|
|
5
5
|
require 'mods_display/country_codes'
|
6
6
|
require 'mods_display/relator_codes'
|
7
7
|
require 'mods_display/related_item_concerns'
|
8
|
+
require 'mods_display/name_formatter'
|
8
9
|
require 'mods_display/fields/field'
|
9
10
|
require 'mods_display/fields/abstract'
|
10
11
|
require 'mods_display/fields/access_condition'
|
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.
|
4
|
+
version: 1.4.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-11-
|
11
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stanford-mods
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/mods_display/fields/title.rb
|
224
224
|
- lib/mods_display/fields/values.rb
|
225
225
|
- lib/mods_display/html.rb
|
226
|
+
- lib/mods_display/name_formatter.rb
|
226
227
|
- lib/mods_display/related_item_concerns.rb
|
227
228
|
- lib/mods_display/relator_codes.rb
|
228
229
|
- lib/mods_display/version.rb
|