mods_display 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- 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,21 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Language < Field
|
3
|
+
def fields
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
next unless value.respond_to?(:languageTerm)
|
5
6
|
value.languageTerm.map do |term|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
next unless term.attributes['type'].respond_to?(:value) && term.attributes['type'].value == 'code'
|
8
|
+
ModsDisplay::Values.new(
|
9
|
+
label: displayLabel(value) || displayLabel(term) || I18n.t('mods_display.language'),
|
10
|
+
values: [displayForm(value) || language_codes[term.text]].flatten
|
11
|
+
)
|
9
12
|
end.flatten.compact
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
end
|
13
|
+
end.flatten.compact
|
14
|
+
collapse_fields(return_fields)
|
15
|
+
end
|
14
16
|
|
15
|
-
|
17
|
+
private
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
def language_codes
|
20
|
+
SEARCHWORKS_LANGUAGES
|
21
|
+
end
|
19
22
|
end
|
20
|
-
|
21
|
-
end
|
23
|
+
end
|
@@ -1,41 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Location < Field
|
3
|
+
def fields
|
4
|
+
return_fields = []
|
5
|
+
@values.each do |location|
|
6
|
+
location.children.each do |child|
|
7
|
+
next unless location_field_keys.include?(child.name.to_sym)
|
8
8
|
if child.name.to_sym == :url
|
9
9
|
loc_label = displayLabel(location) || I18n.t('mods_display.location')
|
10
|
-
value = "<a href='#{child.text}'>#{(displayLabel(child) || child.text).gsub(/:$/,'')}</a>"
|
10
|
+
value = "<a href='#{child.text}'>#{(displayLabel(child) || child.text).gsub(/:$/, '')}</a>"
|
11
11
|
else
|
12
12
|
loc_label = location_label(child) || displayLabel(location) || I18n.t('mods_display.location')
|
13
13
|
value = child.text
|
14
14
|
end
|
15
|
-
return_fields << ModsDisplay::Values.new(
|
16
|
-
|
15
|
+
return_fields << ModsDisplay::Values.new(
|
16
|
+
label: loc_label || displayLabel(location) || I18n.t('mods_display.location'),
|
17
|
+
values: [value]
|
18
|
+
)
|
17
19
|
end
|
18
20
|
end
|
21
|
+
collapse_fields(return_fields)
|
19
22
|
end
|
20
|
-
collapse_fields(return_fields)
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
+
private
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def location_field_keys
|
27
|
+
[:physicalLocation, :url, :shelfLocation, :holdingSimple, :holdingExternal]
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def location_label(element)
|
31
|
+
if displayLabel(element)
|
32
|
+
displayLabel(element)
|
33
|
+
elsif element.attributes['type'].respond_to?(:value) && location_labels.key?(element.attributes['type'].value)
|
34
|
+
location_labels[element.attributes['type'].value]
|
35
|
+
end
|
34
36
|
end
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
def location_labels
|
39
|
+
{ 'repository' => I18n.t('mods_display.repository') }
|
40
|
+
end
|
39
41
|
end
|
40
|
-
|
41
|
-
end
|
42
|
+
end
|
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Name < Field
|
3
|
+
include ModsDisplay::RelatorCodes
|
4
|
+
def fields
|
5
|
+
return_fields = @values.map do |value|
|
6
|
+
roles = process_role(value)
|
7
|
+
person = nil
|
8
|
+
if value.displayForm.length > 0
|
9
|
+
person = ModsDisplay::Name::Person.new(name: value.displayForm.text, roles: roles)
|
10
|
+
elsif !name_parts(value).empty?
|
11
|
+
person = ModsDisplay::Name::Person.new(name: name_parts(value), roles: roles)
|
12
|
+
end
|
13
|
+
ModsDisplay::Values.new(label: displayLabel(value) || name_label(value), values: [person]) if person
|
14
|
+
end.compact
|
15
|
+
collapse_fields(return_fields)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def to_html
|
19
|
+
return nil if fields.empty? || @config.ignore?
|
20
|
+
output = ''
|
21
|
+
fields.each do |field|
|
22
|
+
output << "<dt#{label_class} #{sanitized_field_title(field.label)}>#{field.label}</dt>"
|
23
|
+
output << "<dd#{value_class}>"
|
23
24
|
output << field.values.map do |val|
|
24
25
|
if @config.link
|
25
26
|
txt = link_to_value(val.name)
|
@@ -29,132 +30,126 @@ class ModsDisplay::Name < ModsDisplay::Field
|
|
29
30
|
val.to_s
|
30
31
|
end
|
31
32
|
end.join(@config.delimiter)
|
32
|
-
|
33
|
+
output << '</dd>'
|
34
|
+
end
|
35
|
+
output
|
33
36
|
end
|
34
|
-
output
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
+
private
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def name_label(element)
|
41
|
+
if !role?(element) || primary?(element) || author_or_creator_roles?(element)
|
42
|
+
I18n.t('mods_display.author_creator')
|
43
|
+
else
|
44
|
+
I18n.t('mods_display.contributor')
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def role?(element)
|
49
|
+
element.respond_to?(:role) && !element.role.empty?
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
def primary?(element)
|
53
|
+
element.attributes['usage'].respond_to?(:value) &&
|
54
|
+
element.attributes['usage'].value == 'primary'
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
["author", "aut", "creator", "cre", ""].include?(element.role.roleTerm.text.downcase)
|
57
|
+
def author_or_creator_roles?(element)
|
58
|
+
['author', 'aut', 'creator', 'cre', ''].include?(element.role.roleTerm.text.downcase)
|
59
59
|
rescue
|
60
60
|
false
|
61
61
|
end
|
62
|
-
end
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
def name_parts(element)
|
64
|
+
output = ''
|
65
|
+
output << [unqualified_name_parts(element),
|
66
|
+
qualified_name_parts(element, 'family'),
|
67
|
+
qualified_name_parts(element, 'given')].flatten.compact.join(', ')
|
68
|
+
terms = qualified_name_parts(element, 'termsOfAddress')
|
69
|
+
unless terms.empty?
|
70
|
+
term_delimiter = ', '
|
71
|
+
term_delimiter = ' ' if name_part_begins_with_roman_numeral?(terms.first)
|
72
|
+
output = [output, terms.join(', ')].flatten.compact.join(term_delimiter)
|
74
73
|
end
|
75
|
-
|
74
|
+
dates = qualified_name_parts(element, 'date')
|
75
|
+
unless dates.empty?
|
76
|
+
output = [output, qualified_name_parts(element, 'date')].flatten.compact.join(', ')
|
77
|
+
end
|
78
|
+
output
|
76
79
|
end
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
|
81
|
+
def unqualified_name_parts(element)
|
82
|
+
element.namePart.map do |part|
|
83
|
+
part.text unless part.attributes['type']
|
84
|
+
end.compact
|
80
85
|
end
|
81
|
-
output
|
82
|
-
end
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
def qualified_name_parts(element, type)
|
88
|
+
element.namePart.map do |part|
|
89
|
+
if part.attributes['type'].respond_to?(:value) &&
|
90
|
+
part.attributes['type'].value == type
|
91
|
+
part.text
|
92
|
+
end
|
93
|
+
end.compact
|
94
|
+
end
|
89
95
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
part.text
|
96
|
+
def name_part_begins_with_roman_numeral?(part)
|
97
|
+
first_part = part.split(/\s|,/).first.strip
|
98
|
+
first_part.chars.all? do |char|
|
99
|
+
%w(I X C L V).include? char
|
95
100
|
end
|
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
|
-
["I", "X", "C", "L", "V"].include? char
|
103
101
|
end
|
104
|
-
end
|
105
102
|
|
106
|
-
|
107
|
-
|
103
|
+
def process_role(element)
|
104
|
+
return unless element.role.length > 0 && element.role.roleTerm.length > 0
|
108
105
|
if unencoded_role_term?(element)
|
109
106
|
unencoded_role_term(element)
|
110
107
|
else
|
111
108
|
element.role.roleTerm.map do |term|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
109
|
+
next unless term.attributes['type'].respond_to?(:value) &&
|
110
|
+
term.attributes['type'].value == 'code' &&
|
111
|
+
term.attributes['authority'].respond_to?(:value) &&
|
112
|
+
term.attributes['authority'].value == 'marcrelator' &&
|
113
|
+
relator_codes.include?(term.text.strip)
|
114
|
+
relator_codes[term.text.strip]
|
119
115
|
end.compact
|
120
116
|
end
|
121
117
|
end
|
122
|
-
end
|
123
118
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
+
roles = element.role.map do |role|
|
127
|
+
role.roleTerm.find do |term|
|
128
|
+
!term.attributes['type'].respond_to?(:value)
|
129
|
+
end
|
130
|
+
end.compact if roles.empty?
|
131
|
+
roles.map { |t| t.text.strip }
|
132
|
+
end
|
133
|
+
|
134
|
+
def unencoded_role_term?(element)
|
135
|
+
element.role.roleTerm.any? do |term|
|
136
|
+
!term.attributes['type'].respond_to?(:value) ||
|
137
|
+
term.attributes['type'].value == 'text'
|
129
138
|
end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
139
|
+
end
|
140
|
+
|
141
|
+
class Person
|
142
|
+
attr_accessor :name, :roles
|
143
|
+
def initialize(data)
|
144
|
+
@name = data[:name]
|
145
|
+
@roles = data[:roles] && !data[:roles].empty? ? data[:roles] : nil
|
134
146
|
end
|
135
|
-
end.compact if roles.empty?
|
136
|
-
roles.map{|t| t.text.strip }
|
137
|
-
end
|
138
147
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
class Person
|
147
|
-
attr_accessor :name, :roles
|
148
|
-
def initialize(data)
|
149
|
-
@name = data[:name]
|
150
|
-
@roles = data[:roles] && !data[:roles].empty? ? data[:roles] : nil
|
151
|
-
end
|
152
|
-
|
153
|
-
def to_s
|
154
|
-
text = @name.dup
|
155
|
-
text << " (#{@roles.join(', ')})" if @roles
|
156
|
-
text
|
148
|
+
def to_s
|
149
|
+
text = @name.dup
|
150
|
+
text << " (#{@roles.join(', ')})" if @roles
|
151
|
+
text
|
152
|
+
end
|
157
153
|
end
|
158
154
|
end
|
159
|
-
|
160
|
-
end
|
155
|
+
end
|
@@ -1,41 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Note < Field
|
3
|
+
def fields
|
4
|
+
return_fields = note_fields.map do |value|
|
5
|
+
ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [value.text])
|
6
|
+
end
|
7
|
+
collapse_fields(return_fields)
|
6
8
|
end
|
7
|
-
collapse_fields(return_fields)
|
8
|
-
end
|
9
|
-
|
10
|
-
|
11
|
-
private
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
private
|
11
|
+
|
12
|
+
def note_fields
|
13
|
+
@values.select do |value|
|
14
|
+
(!value.attributes['type'].respond_to?(:value) ||
|
15
|
+
(value.attributes['type'].respond_to?(:value) &&
|
16
|
+
value.attributes['type'].value.downcase != 'contact'))
|
17
|
+
end
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def note_label(element)
|
21
|
+
if element.attributes['type'].respond_to?(:value)
|
22
|
+
return note_labels[element.attributes['type'].value] || "#{element.attributes['type'].value.capitalize}:"
|
23
|
+
end
|
24
|
+
I18n.t('mods_display.note')
|
24
25
|
end
|
25
|
-
I18n.t('mods_display.note')
|
26
|
-
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
27
|
+
def note_labels
|
28
|
+
{ 'statement of responsibility' => I18n.t('mods_display.statement_of_responsibility'),
|
29
|
+
'date/sequential designation' => I18n.t('mods_display.date_sequential_designation'),
|
30
|
+
'publications' => I18n.t('mods_display.publications'),
|
31
|
+
'references' => I18n.t('mods_display.references'),
|
32
|
+
'bibliography' => I18n.t('mods_display.bibliography'),
|
33
|
+
'preferred citation' => I18n.t('mods_display.preferred_citation'),
|
34
|
+
'biographical/historical' => I18n.t('mods_display.biographical_historical'),
|
35
|
+
'creation/production credits' => I18n.t('mods_display.creation_production_credits'),
|
36
|
+
'citation/reference' => I18n.t('mods_display.citation_reference')
|
37
|
+
}
|
38
|
+
end
|
39
39
|
end
|
40
|
-
|
41
|
-
end
|
40
|
+
end
|