mods_display 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/lib/mods_display/fields/imprint.rb +3 -3
- data/lib/mods_display/fields/name.rb +35 -50
- data/lib/mods_display/fields/nested_related_item.rb +3 -3
- data/lib/mods_display/fields/related_item.rb +14 -28
- data/lib/mods_display/related_item_concerns.rb +50 -15
- data/lib/mods_display/version.rb +1 -1
- data/lib/mods_display.rb +2 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b58f76634c11ddf5ce7fef2a844fadbf2d2062ff59f44fc3f903f29fea6d64
|
4
|
+
data.tar.gz: c523ccc3a1534e2eab97a0bc755c52922f4efa5387cf8d2982857fc021b72727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b984e51af9009c0f453d24012574ef6641fbd5d2a9b6d42a4d46386d161314c04533d84e6fe7cee7ea08592bc4a9710f39cc0d2a079fc715c08358377ec1f3
|
7
|
+
data.tar.gz: 33b3ccefd6e79b06f8127421aaa3d6c2cd9241a03c423bed1e0a4f184feb63177781365a7905fbc0094e29d41f6a50f2be1731723bbd6505a808c8deff885367
|
data/.rubocop.yml
CHANGED
@@ -64,12 +64,12 @@ module ModsDisplay
|
|
64
64
|
element.place.respond_to?(:placeTerm)
|
65
65
|
|
66
66
|
if unencoded_place_terms?(element)
|
67
|
-
element.place
|
67
|
+
element.xpath('mods:place/mods:placeTerm', mods: MODS_NS).select do |term|
|
68
68
|
!term.attributes['type'].respond_to?(:value) ||
|
69
69
|
term.attributes['type'].value == 'text'
|
70
70
|
end.compact
|
71
71
|
else
|
72
|
-
element.place
|
72
|
+
element.xpath('mods:place/mods:placeTerm', mods: MODS_NS).map do |term|
|
73
73
|
next unless term.attributes['type'].respond_to?(:value) &&
|
74
74
|
term.attributes['type'].value == 'code' &&
|
75
75
|
term.attributes['authority'].respond_to?(:value) &&
|
@@ -84,7 +84,7 @@ module ModsDisplay
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def unencoded_place_terms?(element)
|
87
|
-
element.place
|
87
|
+
element.xpath('mods:place/mods:placeTerm', mods: MODS_NS).any? do |term|
|
88
88
|
!term.attributes['type'].respond_to?(:value) ||
|
89
89
|
term.attributes['type'].value == 'text'
|
90
90
|
end
|
@@ -7,12 +7,11 @@ 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 = @values.map do |value|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
ModsDisplay::Name::Person.new(name: name_parts(value), name_identifiers: name_identifiers)
|
10
|
+
return_fields = NameValue.for_values(@values).map do |value|
|
11
|
+
person = if value.displayForm_nodeset.length.positive?
|
12
|
+
ModsDisplay::Name::Person.new(name: element_text(value.displayForm_nodeset), name_identifiers: value.nameIdentifier_nodeset)
|
13
|
+
elsif !(name_parts = name_parts(value)).empty?
|
14
|
+
ModsDisplay::Name::Person.new(name: name_parts, name_identifiers: value.nameIdentifier_nodeset)
|
16
15
|
end
|
17
16
|
# The person may have multiple roles, so we have to divide them up into an array
|
18
17
|
role_labels(value).collect do |role_label|
|
@@ -50,10 +49,10 @@ module ModsDisplay
|
|
50
49
|
|
51
50
|
def role_labels(element)
|
52
51
|
default_label = I18n.t('mods_display.associated_with')
|
53
|
-
return [default_label] unless element.role
|
52
|
+
return [default_label] unless element.xpath('mods:role/mods:roleTerm', mods: MODS_NS).present?
|
54
53
|
|
55
|
-
element.
|
56
|
-
codes, text = role.roleTerm.partition { |term| term['type'] == 'code' }
|
54
|
+
element.role_nodeset.collect do |role|
|
55
|
+
codes, text = role.xpath('mods:roleTerm', mods: MODS_NS).partition { |term| term['type'] == 'code' }
|
57
56
|
|
58
57
|
# prefer mappable role term codes
|
59
58
|
label = codes.map { |term| relator_codes[term.text.downcase] }.first
|
@@ -70,15 +69,6 @@ module ModsDisplay
|
|
70
69
|
element_text(element).capitalize.sub(/[.,:;]+$/, '')
|
71
70
|
end
|
72
71
|
|
73
|
-
def role?(element)
|
74
|
-
element.respond_to?(:role) && !element.role.empty?
|
75
|
-
end
|
76
|
-
|
77
|
-
def primary?(element)
|
78
|
-
element.attributes['usage'].respond_to?(:value) &&
|
79
|
-
element.attributes['usage'].value == 'primary'
|
80
|
-
end
|
81
|
-
|
82
72
|
def name_parts(element)
|
83
73
|
output = [unqualified_name_parts(element),
|
84
74
|
qualified_name_parts(element, 'family'),
|
@@ -90,22 +80,19 @@ module ModsDisplay
|
|
90
80
|
output = [output, terms.join(', ')].flatten.compact.join(term_delimiter)
|
91
81
|
end
|
92
82
|
dates = qualified_name_parts(element, 'date')
|
93
|
-
output = [output,
|
83
|
+
output = [output, dates].flatten.compact.join(', ') unless dates.empty?
|
94
84
|
output
|
95
85
|
end
|
96
86
|
|
97
87
|
def unqualified_name_parts(element)
|
98
|
-
element.
|
88
|
+
element.namePart_nodeset.map do |part|
|
99
89
|
element_text(part) unless part.attributes['type']
|
100
90
|
end.compact
|
101
91
|
end
|
102
92
|
|
103
93
|
def qualified_name_parts(element, type)
|
104
|
-
element.
|
105
|
-
if part.
|
106
|
-
part.attributes['type'].value == type
|
107
|
-
element_text(part)
|
108
|
-
end
|
94
|
+
element.namePart_nodeset.map do |part|
|
95
|
+
element_text(part) if part.get_attribute('type') == type
|
109
96
|
end.compact
|
110
97
|
end
|
111
98
|
|
@@ -116,30 +103,6 @@ module ModsDisplay
|
|
116
103
|
end
|
117
104
|
end
|
118
105
|
|
119
|
-
def unencoded_role_term(element)
|
120
|
-
roles = element.role.map do |role|
|
121
|
-
role.roleTerm.find do |term|
|
122
|
-
term.attributes['type'].respond_to?(:value) &&
|
123
|
-
term.attributes['type'].value == 'text'
|
124
|
-
end
|
125
|
-
end.compact
|
126
|
-
if roles.empty?
|
127
|
-
roles = element.role.map do |role|
|
128
|
-
role.roleTerm.find do |term|
|
129
|
-
!term.attributes['type'].respond_to?(:value)
|
130
|
-
end
|
131
|
-
end.compact
|
132
|
-
end
|
133
|
-
roles.map { |t| element_text(t) }
|
134
|
-
end
|
135
|
-
|
136
|
-
def unencoded_role_term?(element)
|
137
|
-
element.role.roleTerm.any? do |term|
|
138
|
-
!term.attributes['type'].respond_to?(:value) ||
|
139
|
-
term.attributes['type'].value == 'text'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
106
|
# Consolidate all names under label headings
|
144
107
|
def consolidate_under_labels(fields)
|
145
108
|
results = {}
|
@@ -194,10 +157,32 @@ module ModsDisplay
|
|
194
157
|
|
195
158
|
def orcid_identifier(name_identifiers)
|
196
159
|
orcid = name_identifiers.select do |name_identifier|
|
197
|
-
name_identifier.
|
160
|
+
name_identifier.get_attribute('type') == 'orcid'
|
198
161
|
end
|
199
162
|
orcid.first&.text
|
200
163
|
end
|
201
164
|
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
|
202
187
|
end
|
203
188
|
end
|
@@ -10,8 +10,8 @@ module ModsDisplay
|
|
10
10
|
|
11
11
|
def fields
|
12
12
|
@fields ||= begin
|
13
|
-
return_fields = @values.map do |value|
|
14
|
-
next if
|
13
|
+
return_fields = RelatedItemValue.for_values(@values).map do |value|
|
14
|
+
next if value.collection?
|
15
15
|
next unless render_nested_related_item?(value)
|
16
16
|
|
17
17
|
related_item_mods_object(value)
|
@@ -63,7 +63,7 @@ module ModsDisplay
|
|
63
63
|
|
64
64
|
def related_item_label(item)
|
65
65
|
return displayLabel(item) if displayLabel(item)
|
66
|
-
return I18n.t('mods_display.constituent') if
|
66
|
+
return I18n.t('mods_display.constituent') if item.constituent?
|
67
67
|
|
68
68
|
I18n.t('mods_display.host')
|
69
69
|
end
|
@@ -5,8 +5,8 @@ module ModsDisplay
|
|
5
5
|
include ModsDisplay::RelatedItemConcerns
|
6
6
|
|
7
7
|
def fields
|
8
|
-
return_fields = @values.map do |value|
|
9
|
-
next if
|
8
|
+
return_fields = RelatedItemValue.for_values(@values).map do |value|
|
9
|
+
next if value.collection?
|
10
10
|
next if render_nested_related_item?(value)
|
11
11
|
|
12
12
|
text = related_item_value(value)
|
@@ -25,15 +25,14 @@ module ModsDisplay
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def related_item_value(item)
|
28
|
-
if
|
29
|
-
element_text(item.
|
30
|
-
elsif
|
28
|
+
if item.location?
|
29
|
+
element_text(item.location_nodeset)
|
30
|
+
elsif item.reference?
|
31
31
|
reference_title(item)
|
32
|
-
elsif item.
|
33
|
-
title = element_text(item.
|
32
|
+
elsif item.titleInfo_nodeset.any?
|
33
|
+
title = element_text(item.titleInfo_nodeset)
|
34
34
|
location = nil
|
35
|
-
location = element_text(item.
|
36
|
-
item.location.url.length.positive?
|
35
|
+
location = element_text(item.location_url_nodeset) if item.location_url_nodeset.length.positive?
|
37
36
|
|
38
37
|
return if title.empty?
|
39
38
|
|
@@ -42,31 +41,18 @@ module ModsDisplay
|
|
42
41
|
else
|
43
42
|
title
|
44
43
|
end
|
45
|
-
elsif item.
|
46
|
-
citation = item.
|
44
|
+
elsif item.note_nodeset.any?
|
45
|
+
citation = item.note_nodeset.find { |note| note['type'] == 'preferred citation' }
|
47
46
|
|
48
47
|
element_text(citation) if citation
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
51
|
def reference_title(item)
|
53
|
-
[item.
|
52
|
+
[item.titleInfo_nodeset,
|
54
53
|
item.originInfo.dateOther,
|
55
54
|
item.part.detail.number,
|
56
|
-
item.
|
57
|
-
end
|
58
|
-
|
59
|
-
def related_item_is_a_location?(item)
|
60
|
-
!related_item_is_a_collection?(item) &&
|
61
|
-
!related_item_is_a_reference?(item) &&
|
62
|
-
item.location.length.positive? &&
|
63
|
-
item.titleInfo.empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
def related_item_is_a_reference?(item)
|
67
|
-
!related_item_is_a_collection?(item) &&
|
68
|
-
item.attributes['type'].respond_to?(:value) &&
|
69
|
-
item.attributes['type'].value == 'isReferencedBy'
|
55
|
+
item.note_nodeset].flatten.compact.map!(&:text).map!(&:strip).join(' ')
|
70
56
|
end
|
71
57
|
|
72
58
|
def related_item_label(item)
|
@@ -74,9 +60,9 @@ module ModsDisplay
|
|
74
60
|
displayLabel(item)
|
75
61
|
else
|
76
62
|
case
|
77
|
-
when
|
63
|
+
when item.location?
|
78
64
|
return I18n.t('mods_display.location')
|
79
|
-
when
|
65
|
+
when item.reference?
|
80
66
|
return I18n.t('mods_display.referenced_by')
|
81
67
|
end
|
82
68
|
I18n.t('mods_display.related_item')
|
@@ -5,25 +5,60 @@ module ModsDisplay
|
|
5
5
|
private
|
6
6
|
|
7
7
|
def render_nested_related_item?(item)
|
8
|
-
|
8
|
+
item.constituent? || item.host?
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
item.typeOfResource.attributes.first.key?('collection') &&
|
16
|
-
item.typeOfResource.attributes.first['collection'].value == 'yes'
|
17
|
-
end
|
11
|
+
class RelatedItemValue < SimpleDelegator
|
12
|
+
def collection?
|
13
|
+
@collection ||= typeOfResource_nodeset.first&.get_attribute('collection') == 'yes'
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
def constituent?
|
17
|
+
@constituent ||= type_attribute == 'constituent'
|
18
|
+
end
|
19
|
+
|
20
|
+
def host?
|
21
|
+
@host ||= type_attribute == 'host'
|
22
|
+
end
|
23
|
+
|
24
|
+
def location?
|
25
|
+
@location ||= !collection? &&
|
26
|
+
!reference? &&
|
27
|
+
location_nodeset.length.positive? &&
|
28
|
+
titleInfo_nodeset.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def reference?
|
32
|
+
@reference ||= !collection? && type_attribute == 'isReferencedBy'
|
33
|
+
end
|
34
|
+
|
35
|
+
def typeOfResource_nodeset
|
36
|
+
@typeOfResource_nodeset ||= xpath('mods:typeOfResource', mods: MODS_NS)
|
37
|
+
end
|
38
|
+
|
39
|
+
def location_nodeset
|
40
|
+
@location_nodeset ||= xpath('mods:location', mods: MODS_NS)
|
41
|
+
end
|
42
|
+
|
43
|
+
def location_url_nodeset
|
44
|
+
@location_url_nodeset ||= xpath('mods:location/mods:url', mods: MODS_NS)
|
45
|
+
end
|
46
|
+
|
47
|
+
def titleInfo_nodeset
|
48
|
+
@titleInfo_nodeset ||= xpath('mods:titleInfo', mods: MODS_NS)
|
49
|
+
end
|
50
|
+
|
51
|
+
def note_nodeset
|
52
|
+
@note_nodeset ||= xpath('mods:note', mods: MODS_NS)
|
53
|
+
end
|
54
|
+
|
55
|
+
def type_attribute
|
56
|
+
@type_attribute ||= get_attribute('type')
|
57
|
+
end
|
23
58
|
|
24
|
-
|
25
|
-
|
26
|
-
|
59
|
+
def self.for_values(values)
|
60
|
+
values.map { |value| new(value) }
|
61
|
+
end
|
27
62
|
end
|
28
63
|
end
|
29
64
|
end
|
data/lib/mods_display/version.rb
CHANGED
data/lib/mods_display.rb
CHANGED
@@ -40,6 +40,8 @@ I18n::Backend::Simple.include I18n::Backend::Fallbacks
|
|
40
40
|
I18n.load_path += Dir["#{File.expand_path('..', __dir__)}/config/locales/*.yml"]
|
41
41
|
I18n.backend.load_translations
|
42
42
|
|
43
|
+
MODS_NS = 'http://www.loc.gov/mods/v3'
|
44
|
+
|
43
45
|
begin
|
44
46
|
require 'rails'
|
45
47
|
rescue LoadError
|
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.3.
|
4
|
+
version: 1.3.5
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: stanford-mods
|
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
245
|
- !ruby/object:Gem::Version
|
246
246
|
version: '0'
|
247
247
|
requirements: []
|
248
|
-
rubygems_version: 3.
|
248
|
+
rubygems_version: 3.3.7
|
249
249
|
signing_key:
|
250
250
|
specification_version: 4
|
251
251
|
summary: The MODS Display gem allows implementers to configure a customized display
|