mods_display 1.0.0.alpha4 → 1.1.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/.rubocop.yml +42 -0
- data/.rubocop_todo.yml +72 -401
- data/Gemfile +4 -1
- data/README.md +0 -63
- data/Rakefile +8 -6
- data/app/components/mods_display/field_component.rb +2 -0
- data/app/components/mods_display/list_field_component.rb +2 -0
- data/app/components/mods_display/record_component.rb +2 -0
- data/app/helpers/mods_display/record_helper.rb +6 -7
- data/app/models/mods_display/record.rb +2 -1
- data/config.ru +2 -2
- data/lib/mods_display/country_codes.rb +2 -1
- data/lib/mods_display/fields/abstract.rb +2 -0
- data/lib/mods_display/fields/access_condition.rb +11 -8
- data/lib/mods_display/fields/audience.rb +2 -0
- data/lib/mods_display/fields/cartographics.rb +11 -4
- data/lib/mods_display/fields/collection.rb +7 -3
- data/lib/mods_display/fields/contact.rb +6 -1
- data/lib/mods_display/fields/contents.rb +2 -0
- data/lib/mods_display/fields/description.rb +4 -3
- data/lib/mods_display/fields/extent.rb +4 -1
- data/lib/mods_display/fields/field.rb +10 -9
- data/lib/mods_display/fields/form.rb +4 -1
- data/lib/mods_display/fields/genre.rb +3 -1
- data/lib/mods_display/fields/geo.rb +5 -2
- data/lib/mods_display/fields/identifier.rb +21 -18
- data/lib/mods_display/fields/imprint.rb +168 -217
- data/lib/mods_display/fields/language.rb +5 -1
- data/lib/mods_display/fields/location.rb +6 -3
- data/lib/mods_display/fields/name.rb +39 -23
- data/lib/mods_display/fields/nested_related_item.rb +18 -2
- data/lib/mods_display/fields/note.rb +10 -8
- data/lib/mods_display/fields/related_item.rb +32 -27
- data/lib/mods_display/fields/resource_type.rb +3 -1
- data/lib/mods_display/fields/sub_title.rb +2 -0
- data/lib/mods_display/fields/subject.rb +17 -50
- data/lib/mods_display/fields/title.rb +39 -28
- data/lib/mods_display/fields/values.rb +2 -0
- data/lib/mods_display/html.rb +4 -3
- data/lib/mods_display/related_item_concerns.rb +4 -2
- data/lib/mods_display/relator_codes.rb +2 -0
- data/lib/mods_display/version.rb +3 -1
- data/lib/mods_display.rb +5 -3
- data/mods_display.gemspec +1 -1
- metadata +14 -8
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Name < Field
|
3
5
|
include ModsDisplay::RelatorCodes
|
4
6
|
def fields
|
5
7
|
return_fields = @values.map do |value|
|
6
|
-
person = if value.displayForm.length
|
7
|
-
ModsDisplay::Name::Person.new(name: value.displayForm
|
8
|
+
person = if value.displayForm.length.positive?
|
9
|
+
ModsDisplay::Name::Person.new(name: element_text(value.displayForm))
|
8
10
|
elsif !name_parts(value).empty?
|
9
11
|
ModsDisplay::Name::Person.new(name: name_parts(value))
|
10
12
|
end
|
@@ -40,11 +42,25 @@ module ModsDisplay
|
|
40
42
|
def role_labels(element)
|
41
43
|
default_label = I18n.t('mods_display.associated_with')
|
42
44
|
return [default_label] unless element.role.present? && element.role.roleTerm.present?
|
43
|
-
|
44
|
-
|
45
|
+
|
46
|
+
element.role.collect do |role|
|
47
|
+
codes, text = role.roleTerm.partition { |term| term['type'] == 'code' }
|
48
|
+
|
49
|
+
# prefer mappable role term codes
|
50
|
+
label = codes.map { |term| relator_codes[term.text.downcase] }.first
|
51
|
+
|
52
|
+
# but fall back to given text
|
53
|
+
label ||= text.map { |term| format_role(term) }.first
|
54
|
+
|
55
|
+
# or just the default
|
56
|
+
label || default_label
|
45
57
|
end.uniq
|
46
58
|
end
|
47
59
|
|
60
|
+
def format_role(element)
|
61
|
+
element_text(element).capitalize.sub(/[.,:;]+$/, '')
|
62
|
+
end
|
63
|
+
|
48
64
|
def role?(element)
|
49
65
|
element.respond_to?(:role) && !element.role.empty?
|
50
66
|
end
|
@@ -55,10 +71,9 @@ module ModsDisplay
|
|
55
71
|
end
|
56
72
|
|
57
73
|
def name_parts(element)
|
58
|
-
output =
|
59
|
-
|
60
|
-
|
61
|
-
qualified_name_parts(element, 'given')].flatten.compact.join(', ')
|
74
|
+
output = [unqualified_name_parts(element),
|
75
|
+
qualified_name_parts(element, 'family'),
|
76
|
+
qualified_name_parts(element, 'given')].flatten.compact.join(', ')
|
62
77
|
terms = qualified_name_parts(element, 'termsOfAddress')
|
63
78
|
unless terms.empty?
|
64
79
|
term_delimiter = ', '
|
@@ -66,15 +81,13 @@ module ModsDisplay
|
|
66
81
|
output = [output, terms.join(', ')].flatten.compact.join(term_delimiter)
|
67
82
|
end
|
68
83
|
dates = qualified_name_parts(element, 'date')
|
69
|
-
unless dates.empty?
|
70
|
-
output = [output, qualified_name_parts(element, 'date')].flatten.compact.join(', ')
|
71
|
-
end
|
84
|
+
output = [output, qualified_name_parts(element, 'date')].flatten.compact.join(', ') unless dates.empty?
|
72
85
|
output
|
73
86
|
end
|
74
87
|
|
75
88
|
def unqualified_name_parts(element)
|
76
89
|
element.namePart.map do |part|
|
77
|
-
part
|
90
|
+
element_text(part) unless part.attributes['type']
|
78
91
|
end.compact
|
79
92
|
end
|
80
93
|
|
@@ -82,7 +95,7 @@ module ModsDisplay
|
|
82
95
|
element.namePart.map do |part|
|
83
96
|
if part.attributes['type'].respond_to?(:value) &&
|
84
97
|
part.attributes['type'].value == type
|
85
|
-
part
|
98
|
+
element_text(part)
|
86
99
|
end
|
87
100
|
end.compact
|
88
101
|
end
|
@@ -90,7 +103,7 @@ module ModsDisplay
|
|
90
103
|
def name_part_begins_with_roman_numeral?(part)
|
91
104
|
first_part = part.split(/\s|,/).first.strip
|
92
105
|
first_part.chars.all? do |char|
|
93
|
-
%w
|
106
|
+
%w[I X C L V].include? char
|
94
107
|
end
|
95
108
|
end
|
96
109
|
|
@@ -98,15 +111,17 @@ module ModsDisplay
|
|
98
111
|
roles = element.role.map do |role|
|
99
112
|
role.roleTerm.find do |term|
|
100
113
|
term.attributes['type'].respond_to?(:value) &&
|
101
|
-
|
114
|
+
term.attributes['type'].value == 'text'
|
102
115
|
end
|
103
116
|
end.compact
|
104
|
-
roles
|
105
|
-
role.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
117
|
+
if roles.empty?
|
118
|
+
roles = element.role.map do |role|
|
119
|
+
role.roleTerm.find do |term|
|
120
|
+
!term.attributes['type'].respond_to?(:value)
|
121
|
+
end
|
122
|
+
end.compact
|
123
|
+
end
|
124
|
+
roles.map { |t| element_text(t) }
|
110
125
|
end
|
111
126
|
|
112
127
|
def unencoded_role_term?(element)
|
@@ -130,7 +145,7 @@ module ModsDisplay
|
|
130
145
|
# Normalize label headings by filtering out some punctuation and ending in :
|
131
146
|
def normalize_labels(label_order, results)
|
132
147
|
label_order.uniq.map do |k|
|
133
|
-
label = k.tr('.', '').tr(':', '').strip
|
148
|
+
label = "#{k.tr('.', '').tr(':', '').strip}:"
|
134
149
|
if label != k
|
135
150
|
results[label] = results[k]
|
136
151
|
results.delete(k)
|
@@ -152,8 +167,9 @@ module ModsDisplay
|
|
152
167
|
|
153
168
|
class Person
|
154
169
|
attr_accessor :name
|
170
|
+
|
155
171
|
def initialize(data)
|
156
|
-
@name =
|
172
|
+
@name = data[:name]
|
157
173
|
end
|
158
174
|
|
159
175
|
def to_s
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
##
|
3
5
|
# This class will hopefully take over for related item support more broadly.
|
@@ -21,7 +23,12 @@ module ModsDisplay
|
|
21
23
|
def to_html(view_context = ApplicationController.renderer)
|
22
24
|
helpers = view_context.respond_to?(:simple_format) ? view_context : ApplicationController.new.view_context
|
23
25
|
|
24
|
-
component = ModsDisplay::ListFieldComponent.with_collection(
|
26
|
+
component = ModsDisplay::ListFieldComponent.with_collection(
|
27
|
+
fields,
|
28
|
+
value_transformer: ->(value) { helpers.link_urls_and_email(value.to_s) },
|
29
|
+
list_html_attributes: { class: 'mods_display_nested_related_items' },
|
30
|
+
list_item_html_attributes: { class: 'mods_display_nested_related_item open' }
|
31
|
+
)
|
25
32
|
|
26
33
|
view_context.render component, layout: false
|
27
34
|
end
|
@@ -29,7 +36,15 @@ module ModsDisplay
|
|
29
36
|
private
|
30
37
|
|
31
38
|
def related_item_mods_object(value)
|
32
|
-
mods = ::Stanford::Mods::Record.new.tap
|
39
|
+
mods = ::Stanford::Mods::Record.new.tap do |r|
|
40
|
+
# dup'ing the value adds the appropriate namespaces, but...
|
41
|
+
munged_node = value.dup.tap do |x|
|
42
|
+
# ... the mods gem also expects the root of the document to have the root tag <mods>
|
43
|
+
x.name = 'mods'
|
44
|
+
end
|
45
|
+
|
46
|
+
r.from_nk_node(munged_node)
|
47
|
+
end
|
33
48
|
related_item = ModsDisplay::HTML.new(mods)
|
34
49
|
|
35
50
|
ModsDisplay::Values.new(
|
@@ -42,6 +57,7 @@ module ModsDisplay
|
|
42
57
|
body = related_item.body
|
43
58
|
|
44
59
|
return if body == '<dl></dl>'
|
60
|
+
|
45
61
|
body
|
46
62
|
end
|
47
63
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Note < Field
|
3
5
|
def fields
|
4
6
|
return_fields = note_fields.map do |value|
|
5
|
-
ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [value
|
7
|
+
ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)])
|
6
8
|
end
|
7
9
|
collapse_fields(return_fields)
|
8
10
|
end
|
@@ -25,20 +27,20 @@ module ModsDisplay
|
|
25
27
|
if element.attributes['type'].respond_to?(:value)
|
26
28
|
return note_labels[element.attributes['type'].value] || "#{element.attributes['type'].value.capitalize}:"
|
27
29
|
end
|
30
|
+
|
28
31
|
I18n.t('mods_display.note')
|
29
32
|
end
|
30
33
|
|
31
34
|
def note_labels
|
32
35
|
{ 'statement of responsibility' => I18n.t('mods_display.statement_of_responsibility'),
|
33
36
|
'date/sequential designation' => I18n.t('mods_display.date_sequential_designation'),
|
34
|
-
'publications'
|
35
|
-
'references'
|
36
|
-
'bibliography'
|
37
|
-
'preferred citation'
|
38
|
-
'biographical/historical'
|
37
|
+
'publications' => I18n.t('mods_display.publications'),
|
38
|
+
'references' => I18n.t('mods_display.references'),
|
39
|
+
'bibliography' => I18n.t('mods_display.bibliography'),
|
40
|
+
'preferred citation' => I18n.t('mods_display.preferred_citation'),
|
41
|
+
'biographical/historical' => I18n.t('mods_display.biographical_historical'),
|
39
42
|
'creation/production credits' => I18n.t('mods_display.creation_production_credits'),
|
40
|
-
'citation/reference'
|
41
|
-
}
|
43
|
+
'citation/reference' => I18n.t('mods_display.citation_reference') }
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class RelatedItem < Field
|
3
5
|
include ModsDisplay::RelatedItemConcerns
|
@@ -6,14 +8,12 @@ module ModsDisplay
|
|
6
8
|
return_fields = @values.map do |value|
|
7
9
|
next if related_item_is_a_collection?(value)
|
8
10
|
next if render_nested_related_item?(value)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
process_related_item(value)
|
16
|
-
end
|
11
|
+
|
12
|
+
text = related_item_value(value)
|
13
|
+
|
14
|
+
next if text.nil? || text.empty?
|
15
|
+
|
16
|
+
ModsDisplay::Values.new(label: related_item_label(value), values: [text])
|
17
17
|
end.compact
|
18
18
|
collapse_fields(return_fields)
|
19
19
|
end
|
@@ -21,27 +21,32 @@ module ModsDisplay
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def delimiter
|
24
|
-
'<br />'
|
24
|
+
'<br />'.html_safe
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
27
|
+
def related_item_value(item)
|
28
|
+
if related_item_is_a_location?(item)
|
29
|
+
element_text(item.location)
|
30
|
+
elsif related_item_is_a_reference?(item)
|
31
|
+
reference_title(item)
|
32
|
+
elsif item.titleInfo.any?
|
33
|
+
title = element_text(item.titleInfo)
|
34
|
+
location = nil
|
35
|
+
location = element_text(item.location.url) if item.location.length.positive? &&
|
36
|
+
item.location.url.length.positive?
|
30
37
|
|
31
|
-
|
32
|
-
ModsDisplay::Values.new(label: related_item_label(item), values: [reference_title(item)])
|
33
|
-
end
|
38
|
+
return if title.empty?
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
return_text = "<a href='#{location}'>#{title}</a>" if location && !title.empty?
|
40
|
+
if location
|
41
|
+
"<a href='#{location}'>#{title}</a>".html_safe
|
42
|
+
else
|
43
|
+
title
|
44
|
+
end
|
45
|
+
elsif item.note.any?
|
46
|
+
citation = item.note.find { |note| note['type'] == 'preferred citation' }
|
43
47
|
|
44
|
-
|
48
|
+
element_text(citation) if citation
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
def reference_title(item)
|
@@ -54,8 +59,8 @@ module ModsDisplay
|
|
54
59
|
def related_item_is_a_location?(item)
|
55
60
|
!related_item_is_a_collection?(item) &&
|
56
61
|
!related_item_is_a_reference?(item) &&
|
57
|
-
item.location.length
|
58
|
-
item.titleInfo.
|
62
|
+
item.location.length.positive? &&
|
63
|
+
item.titleInfo.empty?
|
59
64
|
end
|
60
65
|
|
61
66
|
def related_item_is_a_reference?(item)
|
@@ -66,7 +71,7 @@ module ModsDisplay
|
|
66
71
|
|
67
72
|
def related_item_label(item)
|
68
73
|
if displayLabel(item)
|
69
|
-
|
74
|
+
displayLabel(item)
|
70
75
|
else
|
71
76
|
case
|
72
77
|
when related_item_is_a_location?(item)
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class ResourceType < Field
|
3
5
|
def fields
|
4
6
|
return_fields = @values.map do |value|
|
5
|
-
ModsDisplay::Values.new(label: displayLabel(value) || label, values: [value
|
7
|
+
ModsDisplay::Values.new(label: displayLabel(value) || label, values: [element_text(value)])
|
6
8
|
end
|
7
9
|
collapse_fields(return_fields)
|
8
10
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Subject < Field
|
3
5
|
def fields
|
@@ -7,23 +9,19 @@ module ModsDisplay
|
|
7
9
|
label = displayLabel(value) || I18n.t('mods_display.subject')
|
8
10
|
return_text = []
|
9
11
|
selected_subjects(value).each do |child|
|
10
|
-
if
|
12
|
+
if respond_to?(:"process_#{child.name}")
|
11
13
|
method_send = send(:"process_#{child.name}", child)
|
12
14
|
return_text << method_send unless method_send.to_s.empty?
|
15
|
+
elsif element_text(child).include?('--')
|
16
|
+
return_text << element_text(child).split('--').map(&:strip)
|
13
17
|
else
|
14
|
-
|
15
|
-
return_text << child.text.split('--').map(&:strip)
|
16
|
-
else
|
17
|
-
return_text << child.text unless child.text.empty?
|
18
|
-
end
|
18
|
+
return_text << element_text(child) unless element_text(child).empty?
|
19
19
|
end
|
20
20
|
end
|
21
21
|
return_values << return_text.flatten unless return_text.empty?
|
22
|
-
unless return_values.empty?
|
23
|
-
return_fields << ModsDisplay::Values.new(label: label, values: return_values)
|
24
|
-
end
|
22
|
+
return_fields << ModsDisplay::Values.new(label: label, values: return_values) unless return_values.empty?
|
25
23
|
end
|
26
|
-
|
24
|
+
collapse_fields return_fields
|
27
25
|
end
|
28
26
|
|
29
27
|
# Would really like to clean this up, but it works and is tested for now.
|
@@ -44,7 +42,7 @@ module ModsDisplay
|
|
44
42
|
def process_name(element)
|
45
43
|
name = ModsDisplay::Name.new([element]).fields.first
|
46
44
|
|
47
|
-
name
|
45
|
+
name&.values&.first
|
48
46
|
end
|
49
47
|
|
50
48
|
private
|
@@ -56,54 +54,23 @@ module ModsDisplay
|
|
56
54
|
def values_from_subjects(element)
|
57
55
|
return_values = []
|
58
56
|
selected_subjects(element).each do |child|
|
59
|
-
if child.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
return_values << if element_text(child).include?('--')
|
58
|
+
element_text(child).split('--').map(&:strip)
|
59
|
+
else
|
60
|
+
element_text(child)
|
61
|
+
end
|
64
62
|
end
|
65
63
|
return_values
|
66
64
|
end
|
67
65
|
|
68
66
|
def selected_subjects(element = @value)
|
69
|
-
element.children.
|
70
|
-
|
67
|
+
element.children.reject do |child|
|
68
|
+
omit_elements.include?(child.name.to_sym)
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
74
72
|
def omit_elements
|
75
|
-
[
|
76
|
-
end
|
77
|
-
|
78
|
-
# Providing subject specific collapsing method so we can
|
79
|
-
# collapse the labels w/o flattening all the subject fields.
|
80
|
-
def collapse_subjects(display_fields)
|
81
|
-
return_values = []
|
82
|
-
current_label = nil
|
83
|
-
prev_label = nil
|
84
|
-
buffer = []
|
85
|
-
display_fields.each_with_index do |field, index|
|
86
|
-
current_label = field.label
|
87
|
-
current_values = field.values
|
88
|
-
if display_fields.length == 1
|
89
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
90
|
-
elsif index == (display_fields.length - 1)
|
91
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
92
|
-
if current_label != prev_label
|
93
|
-
return_values << ModsDisplay::Values.new(label: prev_label, values: [buffer.flatten(1)])
|
94
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
95
|
-
else
|
96
|
-
buffer.concat(current_values)
|
97
|
-
return_values << ModsDisplay::Values.new(label: current_label, values: buffer.flatten(0))
|
98
|
-
end
|
99
|
-
elsif prev_label && (current_label != prev_label)
|
100
|
-
return_values << ModsDisplay::Values.new(label: prev_label, values: buffer.flatten(0))
|
101
|
-
buffer = []
|
102
|
-
end
|
103
|
-
buffer.concat(current_values)
|
104
|
-
prev_label = current_label
|
105
|
-
end
|
106
|
-
return_values
|
73
|
+
%i[cartographics geographicCode text]
|
107
74
|
end
|
108
75
|
end
|
109
76
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class Title < Field
|
3
5
|
def fields
|
4
6
|
return_values = []
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
11
|
-
end
|
7
|
+
@values&.each do |value|
|
8
|
+
return_values << ModsDisplay::Values.new(
|
9
|
+
label: displayLabel(value) || title_label(value),
|
10
|
+
values: [assemble_title(value)]
|
11
|
+
)
|
12
12
|
end
|
13
13
|
collapse_fields(return_values)
|
14
14
|
end
|
@@ -16,33 +16,32 @@ module ModsDisplay
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def delimiter
|
19
|
-
'<br />'
|
19
|
+
'<br />'.html_safe
|
20
20
|
end
|
21
21
|
|
22
22
|
def assemble_title(element)
|
23
|
-
return displayForm(element) if displayForm(element)
|
24
|
-
|
25
23
|
title = ''
|
26
24
|
previous_element = nil
|
27
25
|
|
28
26
|
element.children.select { |value| title_parts.include? value.name }.each do |value|
|
29
|
-
str = value
|
27
|
+
str = element_text(value)
|
30
28
|
next if str.empty?
|
31
29
|
|
32
|
-
delimiter =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
delimiter = if title.empty? || title.end_with?(' ')
|
31
|
+
nil
|
32
|
+
elsif previous_element&.name == 'nonSort' && title.end_with?('-', '\'')
|
33
|
+
nil
|
34
|
+
elsif title.end_with?('.', ',', ':', ';')
|
35
|
+
' '
|
36
|
+
elsif value.name == 'subTitle'
|
37
|
+
' : '
|
38
|
+
elsif value.name == 'partName' && previous_element.name == 'partNumber'
|
39
|
+
', '
|
40
|
+
elsif value.name == 'partNumber' || value.name == 'partName'
|
41
|
+
'. '
|
42
|
+
else
|
43
|
+
' '
|
44
|
+
end
|
46
45
|
|
47
46
|
title += delimiter if delimiter
|
48
47
|
title += str
|
@@ -50,7 +49,18 @@ module ModsDisplay
|
|
50
49
|
previous_element = value
|
51
50
|
end
|
52
51
|
|
53
|
-
|
52
|
+
if element['type'] == 'uniform' && element['nameTitleGroup'].present?
|
53
|
+
[uniform_title_name_part(element), title].compact.join('. ')
|
54
|
+
else
|
55
|
+
title
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def uniform_title_name_part(element)
|
60
|
+
names = element.xpath("//m:name[@nameTitleGroup=\"#{element['nameTitleGroup']}\"]", **Mods::Record::NS_HASH)
|
61
|
+
names = element.xpath("//name[@nameTitleGroup=\"#{element['nameTitleGroup']}\"]") if names.empty?
|
62
|
+
|
63
|
+
ModsDisplay::Name.new(names).fields.first&.values&.first&.to_s
|
54
64
|
end
|
55
65
|
|
56
66
|
def title_parts
|
@@ -62,14 +72,15 @@ module ModsDisplay
|
|
62
72
|
title_labels.key?(element.attributes['type'].value)
|
63
73
|
return title_labels[element.attributes['type'].value]
|
64
74
|
end
|
75
|
+
|
65
76
|
I18n.t('mods_display.title')
|
66
77
|
end
|
67
78
|
|
68
79
|
def title_labels
|
69
80
|
{ 'abbreviated' => I18n.t('mods_display.abbreviated_title'),
|
70
|
-
'translated'
|
81
|
+
'translated' => I18n.t('mods_display.translated_title'),
|
71
82
|
'alternative' => I18n.t('mods_display.alternative_title'),
|
72
|
-
'uniform'
|
83
|
+
'uniform' => I18n.t('mods_display.uniform_title') }
|
73
84
|
end
|
74
85
|
end
|
75
86
|
end
|
data/lib/mods_display/html.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
class HTML
|
3
5
|
MODS_DISPLAY_FIELD_MAPPING = {
|
@@ -33,9 +35,8 @@ module ModsDisplay
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def title
|
36
|
-
unless mods_field(:title).fields.empty?
|
37
|
-
|
38
|
-
end
|
38
|
+
return mods_field(:title).fields.first.values unless mods_field(:title).fields.empty?
|
39
|
+
|
39
40
|
''
|
40
41
|
end
|
41
42
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ModsDisplay
|
2
4
|
module RelatedItemConcerns
|
3
5
|
private
|
@@ -16,12 +18,12 @@ module ModsDisplay
|
|
16
18
|
|
17
19
|
def related_item_is_a_constituent?(item)
|
18
20
|
item.attributes['type'].respond_to?(:value) &&
|
19
|
-
|
21
|
+
item.attributes['type'].value == 'constituent'
|
20
22
|
end
|
21
23
|
|
22
24
|
def related_item_is_host?(item)
|
23
25
|
item.attributes['type'].respond_to?(:value) &&
|
24
|
-
|
26
|
+
item.attributes['type'].value == 'host'
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/mods_display/version.rb
CHANGED
data/lib/mods_display.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mods_display/version'
|
2
4
|
require 'mods_display/html'
|
3
5
|
require 'mods_display/country_codes'
|
@@ -34,14 +36,14 @@ require 'stanford-mods'
|
|
34
36
|
|
35
37
|
require 'i18n'
|
36
38
|
require 'i18n/backend/fallbacks'
|
37
|
-
I18n::Backend::Simple.
|
38
|
-
I18n.load_path += Dir["#{File.expand_path('
|
39
|
+
I18n::Backend::Simple.include I18n::Backend::Fallbacks
|
40
|
+
I18n.load_path += Dir["#{File.expand_path('..', __dir__)}/config/locales/*.yml"]
|
39
41
|
I18n.backend.load_translations
|
40
42
|
|
41
43
|
begin
|
42
44
|
require 'rails'
|
43
45
|
rescue LoadError
|
44
|
-
#do nothing
|
46
|
+
# do nothing
|
45
47
|
end
|
46
48
|
|
47
49
|
require 'mods_display/engine' if defined?(Rails)
|
data/mods_display.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.executables = gem.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
22
22
|
gem.require_paths = ["lib"]
|
23
23
|
|
24
|
-
gem.add_dependency 'stanford-mods', '
|
24
|
+
gem.add_dependency 'stanford-mods', '>= 3.0.0.alpha1', '< 4'
|
25
25
|
gem.add_dependency 'i18n'
|
26
26
|
gem.add_dependency 'view_component'
|
27
27
|
|