mods_display 0.3.3 → 0.3.4
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 +16 -0
- data/.rubocop_todo.yml +60 -0
- data/.travis.yml +2 -2
- data/Rakefile +10 -2
- data/lib/mods_display.rb +42 -42
- data/lib/mods_display/configuration.rb +69 -67
- data/lib/mods_display/configuration/access_condition.rb +17 -13
- data/lib/mods_display/configuration/base.rb +27 -24
- data/lib/mods_display/configuration/format.rb +8 -4
- data/lib/mods_display/configuration/genre.rb +8 -4
- data/lib/mods_display/configuration/imprint.rb +12 -7
- data/lib/mods_display/configuration/name.rb +8 -4
- data/lib/mods_display/configuration/note.rb +8 -4
- data/lib/mods_display/configuration/related_item.rb +8 -4
- data/lib/mods_display/configuration/subject.rb +11 -9
- data/lib/mods_display/configuration/title.rb +8 -4
- data/lib/mods_display/controller_extension.rb +24 -24
- data/lib/mods_display/country_codes.rb +385 -384
- data/lib/mods_display/fields/abstract.rb +7 -6
- data/lib/mods_display/fields/access_condition.rb +55 -55
- data/lib/mods_display/fields/audience.rb +7 -6
- data/lib/mods_display/fields/cartographics.rb +15 -14
- data/lib/mods_display/fields/collection.rb +32 -17
- data/lib/mods_display/fields/contact.rb +15 -13
- data/lib/mods_display/fields/contents.rb +7 -6
- data/lib/mods_display/fields/description.rb +21 -21
- data/lib/mods_display/fields/field.rb +164 -109
- data/lib/mods_display/fields/format.rb +36 -33
- data/lib/mods_display/fields/genre.rb +12 -11
- data/lib/mods_display/fields/identifier.rb +34 -34
- data/lib/mods_display/fields/imprint.rb +258 -214
- data/lib/mods_display/fields/language.rb +18 -16
- data/lib/mods_display/fields/location.rb +27 -26
- data/lib/mods_display/fields/name.rb +113 -118
- data/lib/mods_display/fields/note.rb +33 -34
- data/lib/mods_display/fields/related_item.rb +64 -66
- data/lib/mods_display/fields/resource_type.rb +13 -11
- data/lib/mods_display/fields/sub_title.rb +6 -4
- data/lib/mods_display/fields/subject.rb +92 -90
- data/lib/mods_display/fields/title.rb +54 -49
- data/lib/mods_display/fields/values.rb +7 -8
- data/lib/mods_display/html.rb +117 -96
- data/lib/mods_display/model_extension.rb +17 -16
- data/lib/mods_display/relator_codes.rb +269 -267
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +13 -12
- data/spec/configuration/access_condition_spec.rb +5 -5
- data/spec/configuration/base_spec.rb +24 -24
- data/spec/fields/abstract_spec.rb +24 -14
- data/spec/fields/access_condition_spec.rb +80 -55
- data/spec/fields/audience_spec.rb +15 -12
- data/spec/fields/cartographics_spec.rb +17 -18
- data/spec/fields/collection_spec.rb +65 -19
- data/spec/fields/contact_spec.rb +11 -9
- data/spec/fields/contents_spec.rb +15 -12
- data/spec/fields/description_spec.rb +40 -22
- data/spec/fields/format_spec.rb +28 -18
- data/spec/fields/genre_spec.rb +18 -16
- data/spec/fields/identifier_spec.rb +46 -34
- data/spec/fields/imprint_spec.rb +151 -125
- data/spec/fields/language_spec.rb +36 -20
- data/spec/fields/location_spec.rb +43 -27
- data/spec/fields/name_spec.rb +92 -92
- data/spec/fields/note_spec.rb +53 -40
- data/spec/fields/related_item_spec.rb +42 -40
- data/spec/fields/resource_type_spec.rb +20 -14
- data/spec/fields/sub_title_spec.rb +11 -9
- data/spec/fields/subject_spec.rb +61 -56
- data/spec/fields/title_spec.rb +53 -40
- data/spec/fixtures/access_condition_fixtures.rb +50 -0
- data/spec/fixtures/cartographics_fixtures.rb +1 -1
- data/spec/fixtures/imprint_fixtures.rb +49 -1
- data/spec/fixtures/name_fixtures.rb +195 -2
- data/spec/fixtures/related_item_fixtures.rb +107 -0
- data/spec/fixtures/subjects_fixtures.rb +15 -2
- data/spec/fixtures/title_fixtures.rb +101 -0
- data/spec/integration/configuration_spec.rb +23 -20
- data/spec/integration/html_spec.rb +40 -29
- data/spec/integration/installation_spec.rb +14 -14
- data/spec/spec_helper.rb +5 -8
- metadata +25 -3
@@ -1,84 +1,82 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class RelatedItem < Field
|
3
|
+
def fields
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
next if related_item_is_a_collection?(value)
|
6
6
|
case
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
when related_item_is_a_location?(value)
|
8
|
+
process_location value
|
9
|
+
when related_item_is_a_reference?(value)
|
10
|
+
process_reference value
|
11
|
+
else
|
12
|
+
process_related_item(value)
|
13
13
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
end
|
14
|
+
end.compact
|
15
|
+
collapse_fields(return_fields)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
private
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def process_location(item)
|
21
|
+
ModsDisplay::Values.new(label: related_item_label(item), values: [item.location.text.strip])
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def process_reference(item)
|
25
|
+
ModsDisplay::Values.new(label: related_item_label(item), values: [reference_title(item)])
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
28
|
+
def process_related_item(item)
|
29
|
+
return unless item.titleInfo.length > 0
|
31
30
|
title = item.titleInfo.text.strip
|
32
31
|
return_text = title
|
33
32
|
location = nil
|
34
|
-
location = item.location.url.text if
|
35
|
-
|
36
|
-
return_text = "<a href='#{location}'>#{title}</a>" if location
|
37
|
-
|
38
|
-
|
39
|
-
end
|
33
|
+
location = item.location.url.text if item.location.length > 0 &&
|
34
|
+
item.location.url.length > 0
|
35
|
+
return_text = "<a href='#{location}'>#{title}</a>" if location && !title.empty?
|
36
|
+
|
37
|
+
ModsDisplay::Values.new(label: related_item_label(item), values: [return_text]) unless return_text.empty?
|
40
38
|
end
|
41
|
-
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
def reference_title(item)
|
41
|
+
[item.titleInfo,
|
42
|
+
item.originInfo.dateOther,
|
43
|
+
item.part.detail.number,
|
44
|
+
item.note].flatten.compact.map!(&:text).map!(&:strip).join(' ')
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
def related_item_is_a_collection?(item)
|
48
|
+
item.respond_to?(:titleInfo) &&
|
49
|
+
item.respond_to?(:typeOfResource) &&
|
50
|
+
item.typeOfResource.attributes.length > 0 &&
|
51
|
+
item.typeOfResource.attributes.first.key?('collection') &&
|
52
|
+
item.typeOfResource.attributes.first['collection'].value == 'yes'
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
def related_item_is_a_location?(item)
|
56
|
+
!related_item_is_a_collection?(item) &&
|
57
|
+
!related_item_is_a_reference?(item) &&
|
58
|
+
item.location.length > 0 &&
|
59
|
+
item.titleInfo.length < 1
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
def related_item_is_a_reference?(item)
|
63
|
+
!related_item_is_a_collection?(item) &&
|
64
|
+
item.attributes['type'].respond_to?(:value) &&
|
65
|
+
item.attributes['type'].value == 'isReferencedBy'
|
66
|
+
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
68
|
+
def related_item_label(item)
|
69
|
+
if displayLabel(item)
|
70
|
+
return displayLabel(item)
|
71
|
+
else
|
72
|
+
case
|
73
|
+
when related_item_is_a_location?(item)
|
74
|
+
return I18n.t('mods_display.location')
|
75
|
+
when related_item_is_a_reference?(item)
|
76
|
+
return I18n.t('mods_display.referenced_by')
|
77
|
+
end
|
78
|
+
I18n.t('mods_display.related_item')
|
80
79
|
end
|
81
|
-
I18n.t('mods_display.related_item')
|
82
80
|
end
|
83
81
|
end
|
84
|
-
end
|
82
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class ResourceType < Field
|
3
|
+
def fields
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
ModsDisplay::Values.new(label: displayLabel(value) || label, values: [value.text.strip.capitalize].flatten)
|
6
|
+
end
|
7
|
+
collapse_fields(return_fields)
|
6
8
|
end
|
7
|
-
collapse_fields(return_fields)
|
8
|
-
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
private
|
11
|
+
|
12
|
+
def displayLabel(element)
|
13
|
+
super(element) || I18n.t('mods_display.type_of_resource')
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class SubTitle < Field
|
3
|
+
def fields
|
4
|
+
ModsDisplay::Title.new(@values[1, @values.length], @config, @klass).fields
|
5
|
+
end
|
4
6
|
end
|
5
|
-
end
|
7
|
+
end
|
@@ -1,39 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if child.text.include?("--")
|
14
|
-
return_text << child.text.split("--").map{|t| t.strip }
|
1
|
+
module ModsDisplay
|
2
|
+
class Subject < Field
|
3
|
+
def fields
|
4
|
+
return_fields = []
|
5
|
+
@values.each do |value|
|
6
|
+
return_values = []
|
7
|
+
label = displayLabel(value) || I18n.t('mods_display.subject')
|
8
|
+
return_text = []
|
9
|
+
selected_subjects(value).each do |child|
|
10
|
+
if self.respond_to?(:"process_#{child.name}")
|
11
|
+
method_send = send(:"process_#{child.name}", child)
|
12
|
+
return_text << method_send unless method_send.to_s.empty?
|
15
13
|
else
|
16
|
-
|
14
|
+
if child.text.include?('--')
|
15
|
+
return_text << child.text.split('--').map(&:strip)
|
16
|
+
else
|
17
|
+
return_text << child.text unless child.text.empty?
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
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
|
19
25
|
end
|
20
|
-
|
21
|
-
return_values << return_text.flatten
|
22
|
-
end
|
23
|
-
unless return_values.empty?
|
24
|
-
return_fields << ModsDisplay::Values.new(:label => label, :values => return_values)
|
25
|
-
end
|
26
|
+
collapse_subjects return_fields
|
26
27
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
|
36
|
-
output << "<dd#{value_class}>"
|
28
|
+
|
29
|
+
# Would really like to clean this up, but it works and is tested for now.
|
30
|
+
def to_html
|
31
|
+
return nil if fields.empty? || @config.ignore?
|
32
|
+
output = ''
|
33
|
+
fields.each do |field|
|
34
|
+
output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
|
35
|
+
output << "<dd#{value_class}>"
|
37
36
|
subs = []
|
38
37
|
field.values.each do |subjects|
|
39
38
|
buffer = []
|
@@ -44,7 +43,7 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
44
43
|
else
|
45
44
|
buffer << val
|
46
45
|
end
|
47
|
-
if @config.link
|
46
|
+
if @config.link && @config.hierarchical_link
|
48
47
|
if val.is_a?(ModsDisplay::Name::Person)
|
49
48
|
txt = link_to_value(val.name, buffer.join(' '))
|
50
49
|
txt << " (#{val.roles.join(', ')})" if val.roles
|
@@ -66,72 +65,75 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
66
65
|
end
|
67
66
|
subs << sub_parts.join(@config.delimiter)
|
68
67
|
end
|
69
|
-
output << subs.join(
|
70
|
-
|
68
|
+
output << subs.join('<br/>')
|
69
|
+
output << '</dd>'
|
70
|
+
end
|
71
|
+
output
|
71
72
|
end
|
72
|
-
output
|
73
|
-
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
74
|
+
def process_hierarchicalGeographic(element)
|
75
|
+
values_from_subjects(element)
|
76
|
+
end
|
77
|
+
|
78
|
+
def process_name(element)
|
79
|
+
name = ModsDisplay::Name.new([element], @config, @klass).fields.first
|
80
|
+
|
81
|
+
name.values.first if name
|
82
|
+
end
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
private
|
85
|
+
|
86
|
+
def values_from_subjects(element)
|
87
|
+
return_values = []
|
88
|
+
selected_subjects(element).each do |child|
|
89
|
+
if child.text.include?('--')
|
90
|
+
return_values << child.text.split('--').map(&:strip)
|
91
|
+
else
|
92
|
+
return_values << child.text.strip
|
93
|
+
end
|
92
94
|
end
|
95
|
+
return_values
|
93
96
|
end
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
!omit_elements.include?(child.name.to_sym)
|
97
|
+
|
98
|
+
def selected_subjects(element = @value)
|
99
|
+
element.children.select do |child|
|
100
|
+
!omit_elements.include?(child.name.to_sym)
|
101
|
+
end
|
100
102
|
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def omit_elements
|
104
|
-
[:cartographics, :geographicCode, :text]
|
105
|
-
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
current_label =
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if
|
122
|
-
return_values << ModsDisplay::Values.new(:
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
104
|
+
def omit_elements
|
105
|
+
[:cartographics, :geographicCode, :text]
|
106
|
+
end
|
107
|
+
|
108
|
+
# Providing subject specific collapsing method so we can
|
109
|
+
# collapse the labels w/o flattening all the subject fields.
|
110
|
+
def collapse_subjects(display_fields)
|
111
|
+
return_values = []
|
112
|
+
current_label = nil
|
113
|
+
prev_label = nil
|
114
|
+
buffer = []
|
115
|
+
display_fields.each_with_index do |field, index|
|
116
|
+
current_label = field.label
|
117
|
+
current_values = field.values
|
118
|
+
if display_fields.length == 1
|
119
|
+
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
120
|
+
elsif index == (display_fields.length - 1)
|
121
|
+
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
122
|
+
if current_label != prev_label
|
123
|
+
return_values << ModsDisplay::Values.new(label: prev_label, values: [buffer.flatten(1)])
|
124
|
+
return_values << ModsDisplay::Values.new(label: current_label, values: current_values)
|
125
|
+
else
|
126
|
+
buffer.concat(current_values)
|
127
|
+
return_values << ModsDisplay::Values.new(label: current_label, values: buffer.flatten(0))
|
128
|
+
end
|
129
|
+
elsif prev_label && (current_label != prev_label)
|
130
|
+
return_values << ModsDisplay::Values.new(label: prev_label, values: buffer.flatten(0))
|
131
|
+
buffer = []
|
127
132
|
end
|
128
|
-
|
129
|
-
|
130
|
-
buffer = []
|
133
|
+
buffer.concat(current_values)
|
134
|
+
prev_label = current_label
|
131
135
|
end
|
132
|
-
|
133
|
-
prev_label = current_label
|
136
|
+
return_values
|
134
137
|
end
|
135
|
-
return_values
|
136
138
|
end
|
137
|
-
end
|
139
|
+
end
|
@@ -1,59 +1,64 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
[
|
22
|
-
|
23
|
-
child
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Title < Field
|
3
|
+
def fields
|
4
|
+
return_values = []
|
5
|
+
if @values
|
6
|
+
@values.each do |value|
|
7
|
+
if displayForm(value)
|
8
|
+
return_values << ModsDisplay::Values.new(
|
9
|
+
label: displayLabel(value) || title_label(value),
|
10
|
+
values: [displayForm(value)]
|
11
|
+
)
|
12
|
+
else
|
13
|
+
nonSort = nil
|
14
|
+
title = nil
|
15
|
+
subTitle = nil
|
16
|
+
nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
|
17
|
+
title = value.title.text.strip unless value.title.text.strip.empty?
|
18
|
+
subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
|
19
|
+
preSubTitle = [nonSort, title].compact.join(' ')
|
20
|
+
preSubTitle = nil if preSubTitle.strip.empty?
|
21
|
+
preParts = compact_and_join_with_delimiter([preSubTitle, subTitle], ' : ')
|
22
|
+
preParts = nil if preParts.strip.empty?
|
23
|
+
parts = value.children.select do |child|
|
24
|
+
%w(partName partNumber).include?(child.name)
|
25
|
+
end.map(&:text).compact.join(parts_delimiter(value))
|
26
|
+
parts = nil if parts.strip.empty?
|
27
|
+
return_values << ModsDisplay::Values.new(
|
28
|
+
label: displayLabel(value) || title_label(value),
|
29
|
+
values: [compact_and_join_with_delimiter([preParts, parts], '. ')]
|
30
|
+
)
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
34
|
+
collapse_fields(return_values)
|
29
35
|
end
|
30
|
-
collapse_fields(return_values)
|
31
|
-
end
|
32
36
|
|
33
|
-
|
37
|
+
private
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
def parts_delimiter(element)
|
40
|
+
children = element.children.to_a
|
41
|
+
# index will retun nil which is not comparable so we call 100
|
42
|
+
# if the element isn't present (thus meaning it's at the end of the list)
|
43
|
+
if (children.index { |c| c.name == 'partNumber' } || 100) < (children.index { |c| c.name == 'partName' } || 100)
|
44
|
+
return ', '
|
45
|
+
end
|
46
|
+
'. '
|
40
47
|
end
|
41
|
-
". "
|
42
|
-
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
def title_label(element)
|
50
|
+
if element.attributes['type'].respond_to?(:value) &&
|
51
|
+
title_labels.key?(element.attributes['type'].value)
|
52
|
+
return title_labels[element.attributes['type'].value]
|
53
|
+
end
|
54
|
+
I18n.t('mods_display.title')
|
48
55
|
end
|
49
|
-
I18n.t('mods_display.title')
|
50
|
-
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
def title_labels
|
58
|
+
{ 'abbreviated' => I18n.t('mods_display.abbreviated_title'),
|
59
|
+
'translated' => I18n.t('mods_display.translated_title'),
|
60
|
+
'alternative' => I18n.t('mods_display.alternative_title'),
|
61
|
+
'uniform' => I18n.t('mods_display.uniform_title') }
|
62
|
+
end
|
57
63
|
end
|
58
|
-
|
59
|
-
end
|
64
|
+
end
|