mods_display 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c2bc98c15b659a075bccc6e3dea41e55f757f3318ad4d1e34109c314d10792
4
- data.tar.gz: 3fc189b77cd0088578718fa5f1645e5390c0442825faacc51e7ec9de92f568c7
3
+ metadata.gz: 5a10b1a255b452e15abe4bb8efefa442a09e17722689eeada14c2e5b210f80f8
4
+ data.tar.gz: 6cb1fb4fa43419a3820e303cec2da27c9c03d2bd3d4e2db32d3d4189071207e1
5
5
  SHA512:
6
- metadata.gz: 2a35e824baad68b451eb64f126a3eea9eb61c0fd190c767933c4f6946336034d5f604fa8f81a24c1060ab9e29ed7c9d72c941f526b7bf42288870e51862d60fc
7
- data.tar.gz: 9fbd968fe4409450090e9f3285a19f9eb86f3834ddf36061e6d4b5d5c617efaeb2996cdc88a8363a6cb29e79525403578e62266b0873423266d85ea484c461ed
6
+ metadata.gz: 221cf2e30ffc91d3c11afdc2c200552577d7bd2b7975b022bf897668b1342edd7d9a3d21c0cc2724d48ad30b0d1a0be2af46cbab15cc398072aeb5761387d80c
7
+ data.tar.gz: 6f945ced7697570d76661f72e6a16d81fd03a32225f669e133c4e8428f03c1d816b282a2c40c9217d23af23a5f5ff6f49fe807917fbbfbafc34ac1f414f911d6
data/.rubocop.yml CHANGED
@@ -12,11 +12,6 @@ AllCops:
12
12
  TargetRubyVersion: 2.7
13
13
  NewCops: enable
14
14
 
15
- # Warn only for long lines
16
- Layout/LineLength:
17
- Max: 120
18
- Severity: warning
19
-
20
15
  # Use single-quoted strings where possible
21
16
  Style/StringLiterals:
22
17
  Enabled: true
@@ -34,26 +29,4 @@ RSpec/MultipleExpectations:
34
29
  Enabled: false
35
30
 
36
31
  RSpec/ExampleLength:
37
- Enabled: false
38
-
39
- # Warn only for complexity-related metrics
40
- Metrics/MethodLength:
41
- Severity: warning
42
-
43
- Metrics/ClassLength:
44
- Severity: warning
45
-
46
- Metrics/BlockLength:
47
- Severity: warning
48
-
49
- Metrics/ModuleLength:
50
- Severity: warning
51
-
52
- Metrics/PerceivedComplexity:
53
- Severity: warning
54
-
55
- Metrics/CyclomaticComplexity:
56
- Severity: warning
57
-
58
- Metrics/AbcSize:
59
- Severity: warning
32
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,17 +1,15 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-01-24 23:44:41 UTC using RuboCop version 1.25.0.
3
+ # on 2023-10-25 22:18:52 UTC using RuboCop version 1.57.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 28
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
12
- # URISchemes: http, https
13
- Layout/LineLength:
14
- Max: 255
9
+ # Offense count: 1
10
+ Capybara/SpecificMatcher:
11
+ Exclude:
12
+ - 'spec/helpers/record_helper_spec.rb'
15
13
 
16
14
  # Offense count: 2
17
15
  # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
@@ -24,43 +22,39 @@ Lint/ShadowingOuterLocalVariable:
24
22
  Exclude:
25
23
  - 'spec/helpers/record_helper_spec.rb'
26
24
 
27
- # Offense count: 18
28
- # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
25
+ # Offense count: 16
26
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
29
27
  Metrics/AbcSize:
30
- Max: 48
31
-
32
- # Offense count: 37
33
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
34
- # IgnoredMethods: refine
35
- Metrics/BlockLength:
36
- Max: 257
28
+ Max: 44
37
29
 
38
30
  # Offense count: 3
39
31
  # Configuration parameters: CountComments, CountAsOne.
40
32
  Metrics/ClassLength:
41
- Max: 298
33
+ Max: 146
34
+
35
+ # Offense count: 1
36
+ # Configuration parameters: LengthThreshold.
37
+ Metrics/CollectionLiteralLength:
38
+ Exclude:
39
+ - 'lib/mods_display/relator_codes.rb'
42
40
 
43
- # Offense count: 11
44
- # Configuration parameters: IgnoredMethods.
41
+ # Offense count: 10
42
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
45
43
  Metrics/CyclomaticComplexity:
46
44
  Max: 18
47
45
 
48
- # Offense count: 21
49
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
46
+ # Offense count: 16
47
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
50
48
  Metrics/MethodLength:
51
- Max: 378
52
-
53
- # Offense count: 2
54
- # Configuration parameters: CountComments, CountAsOne.
55
- Metrics/ModuleLength:
56
- Max: 380
49
+ Max: 29
57
50
 
58
51
  # Offense count: 8
59
- # Configuration parameters: IgnoredMethods.
52
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
60
53
  Metrics/PerceivedComplexity:
61
54
  Max: 20
62
55
 
63
56
  # Offense count: 1
57
+ # This cop supports unsafe autocorrection (--autocorrect-all).
64
58
  # Configuration parameters: EnforcedStyleForLeadingUnderscores.
65
59
  # SupportedStylesForLeadingUnderscores: disallowed, required, optional
66
60
  Naming/MemoizedInstanceVariableName:
@@ -68,7 +62,7 @@ Naming/MemoizedInstanceVariableName:
68
62
  - 'lib/mods_display/fields/geo.rb'
69
63
 
70
64
  # Offense count: 7
71
- # Configuration parameters: EnforcedStyle, IgnoredPatterns.
65
+ # Configuration parameters: EnforcedStyle, AllowedPatterns.
72
66
  # SupportedStyles: snake_case, camelCase
73
67
  Naming/MethodName:
74
68
  Exclude:
@@ -80,12 +74,12 @@ Naming/MethodName:
80
74
  - 'lib/mods_display/fields/resource_type.rb'
81
75
  - 'lib/mods_display/fields/subject.rb'
82
76
 
83
- # Offense count: 19
77
+ # Offense count: 18
84
78
  RSpec/BeforeAfterAll:
85
79
  Enabled: false
86
80
 
87
81
  # Offense count: 2
88
- # Configuration parameters: Prefixes.
82
+ # Configuration parameters: Prefixes, AllowedPatterns.
89
83
  # Prefixes: when, with, without
90
84
  RSpec/ContextWording:
91
85
  Exclude:
@@ -104,10 +98,10 @@ RSpec/DescribeClass:
104
98
  - 'spec/integration/html_spec.rb'
105
99
 
106
100
  # Offense count: 1
107
- # Cop supports --auto-correct.
101
+ # This cop supports safe autocorrection (--autocorrect).
108
102
  RSpec/ExpectActual:
109
103
  Exclude:
110
- - 'spec/routing/**/*'
104
+ - '**/spec/routing/**/*'
111
105
  - 'spec/fields/name_spec.rb'
112
106
 
113
107
  # Offense count: 25
@@ -116,7 +110,7 @@ RSpec/ExpectActual:
116
110
  RSpec/FilePath:
117
111
  Enabled: false
118
112
 
119
- # Offense count: 111
113
+ # Offense count: 99
120
114
  # Configuration parameters: AssignmentOnly.
121
115
  RSpec/InstanceVariable:
122
116
  Enabled: false
@@ -139,13 +133,22 @@ RSpec/MultipleMemoizedHelpers:
139
133
  Max: 6
140
134
 
141
135
  # Offense count: 2
136
+ # Configuration parameters: AllowedGroups.
142
137
  RSpec/NestedGroups:
143
138
  Max: 4
144
139
 
145
- # Offense count: 2
146
- RSpec/RepeatedExampleGroupDescription:
140
+ # Offense count: 1
141
+ # This cop supports unsafe autocorrection (--autocorrect-all).
142
+ # Configuration parameters: Inferences.
143
+ RSpec/Rails/InferredSpecType:
147
144
  Exclude:
148
- - 'spec/integration/html_spec.rb'
145
+ - 'spec/helpers/record_helper_spec.rb'
146
+
147
+ # Offense count: 25
148
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
149
+ # Include: **/*_spec.rb
150
+ RSpec/SpecFilePathFormat:
151
+ Enabled: false
149
152
 
150
153
  # Offense count: 1
151
154
  # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
@@ -153,7 +156,7 @@ RSpec/VerifiedDoubles:
153
156
  Exclude:
154
157
  - 'spec/helpers/record_helper_spec.rb'
155
158
 
156
- # Offense count: 35
159
+ # Offense count: 36
157
160
  # Configuration parameters: AllowedConstants.
158
161
  Style/Documentation:
159
162
  Enabled: false
@@ -176,9 +179,9 @@ Style/OpenStructUse:
176
179
  Exclude:
177
180
  - 'spec/helpers/record_helper_spec.rb'
178
181
 
179
- # Offense count: 28
180
- # Cop supports --auto-correct.
181
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
182
+ # Offense count: 33
183
+ # This cop supports safe autocorrection (--autocorrect).
184
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
182
185
  # URISchemes: http, https
183
186
  Layout/LineLength:
184
- Max: 255
187
+ Max: 273
data/Gemfile CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'rubocop-rspec', require: false
6
5
  gem 'debug'
6
+ gem 'rubocop-rspec', require: false
7
7
 
8
8
  # Specify your gem's dependencies in mods_display.gemspec
9
9
  gemspec
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
- [![Build Status](https://travis-ci.org/sul-dlss/mods_display.png?branch=master)](https://travis-ci.org/sul-dlss/mods_display)
2
-
3
1
  # ModsDisplay
4
2
 
5
3
  A gem for displaying MODS Metadata in a configurable way.
data/Rakefile CHANGED
@@ -4,11 +4,7 @@ require 'bundler/gem_tasks'
4
4
  require 'rspec/core/rake_task'
5
5
  require 'rubocop/rake_task'
6
6
 
7
- RuboCop::RakeTask.new do |task|
8
- task.requires << 'rubocop-rspec'
9
- task.options = ['--fail-level', 'error']
10
- end
11
-
7
+ RuboCop::RakeTask.new(:rubocop)
12
8
  RSpec::Core::RakeTask.new(:spec)
13
9
 
14
10
  task :ci do
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rails_autolink/helpers'
4
+
3
5
  module ModsDisplay
4
6
  module RecordHelper
5
7
  def mods_display_label(label)
@@ -69,43 +71,21 @@ module ModsDisplay
69
71
  link
70
72
  end
71
73
 
72
- def format_mods_html(val, tags: %w[a dl dd dt i b em strong cite br], field: nil)
73
- val = val.gsub(%r{<[^/> ]+}) do |possible_tag|
74
- # Allow potentially valid HTML tags through to the sanitizer step, and HTML escape the rest
75
- if tags.include?(possible_tag[1..])
76
- possible_tag
77
- else
78
- "&lt;#{possible_tag[1..]}"
79
- end
74
+ class MetadataScrubber < Rails::Html::PermitScrubber
75
+ # Override the superclass to escape the non-permitted nodes
76
+ def scrub_node(node)
77
+ node.add_next_sibling Nokogiri::XML::Text.new(node.to_s, node.document)
78
+ node.remove
80
79
  end
80
+ end
81
81
 
82
- val = val.gsub(%r{</[^> ]+}) do |possible_tag|
83
- # Allow potentially valid HTML tags through to the sanitizer step, and HTML escape the rest
84
- if tags.include?(possible_tag[2..])
85
- possible_tag
86
- else
87
- "&lt;#{possible_tag[1..]}"
88
- end
89
- end
82
+ def format_mods_html(val, tags: %w[a dl dd dt i b em strong cite br], field: nil)
83
+ scrubber = MetadataScrubber.new
84
+ scrubber.tags = tags
90
85
 
91
- # http://daringfireball.net/2010/07/improved_regex_for_matching_urls
92
- url = %r{(?i)\b(?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\([^\s()<>]+|\([^\s()<>]+\)*\))+(?:\([^\s()<>]+|\([^\s()<>]+\)*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])}i
93
- # http://www.regular-expressions.info/email.html
94
- email = %r{[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b}i
95
- matches = [val.scan(url), val.scan(email)].flatten.uniq
96
- unless val =~ /<a/ # we'll assume that linking has alraedy occured and we don't want to double link
97
- matches.each do |match|
98
- if match =~ email
99
- val.gsub!(match, "<a href='mailto:#{match}'>#{match}</a>")
100
- else
101
- match = match.delete_suffix('&gt')
102
-
103
- val.gsub!(match, "<a href='#{match}'>#{match}</a>")
104
- end
105
- end
106
- end
86
+ formatted_val = Loofah.fragment(val).scrub!(scrubber).to_s
107
87
 
108
- formatted_val = sanitize val, tags: tags, attributes: %w[href]
88
+ formatted_val = auto_link(formatted_val) unless formatted_val =~ /<a/ # we'll assume that linking has alraedy occured and we don't want to double link
109
89
 
110
90
  # Martin Wong data has significant linebreaks in abstracts and notes that we want
111
91
  # to preserve and display in HTML.
@@ -115,15 +95,13 @@ module ModsDisplay
115
95
  if simple_formatted_fields.any? { |klass| field&.field.is_a? klass } && formatted_val.include?("\n")
116
96
  simple_format(formatted_val, {}, sanitize: false)
117
97
  else
118
- formatted_val
98
+ formatted_val.html_safe
119
99
  end
120
100
  end
121
101
 
122
- # rubocop:disable Layout/LineLength
123
102
  # @private, but used in PURL currently
124
103
  def link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])
125
104
  format_mods_html(val, tags: tags)
126
105
  end
127
- # rubocop:enable Layout/LineLength
128
106
  end
129
107
  end
@@ -1,388 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mods/marc_country_codes'
4
+
3
5
  module ModsDisplay
4
6
  module CountryCodes
5
7
  def country_codes
6
- { 'aa' => 'Albania',
7
- 'abc' => 'Alberta',
8
- 'ac' => 'Ashmore and Cartier Islands',
9
- 'aca' => 'Australian Capital Territory',
10
- 'ae' => 'Algeria',
11
- 'af' => 'Afghanistan',
12
- 'ag' => 'Argentina',
13
- 'ai' => 'Armenia (Republic)',
14
- 'air' => 'Armenian S.S.R.',
15
- 'aj' => 'Azerbaijan',
16
- 'ajr' => 'Azerbaijan S.S.R.',
17
- 'aku' => 'Alaska',
18
- 'alu' => 'Alabama',
19
- 'am' => 'Anguilla',
20
- 'an' => 'Andorra',
21
- 'ao' => 'Angola',
22
- 'aq' => 'Antigua and Barbuda',
23
- 'aru' => 'Arkansas',
24
- 'as' => 'American Samoa',
25
- 'at' => 'Australia',
26
- 'au' => 'Austria',
27
- 'aw' => 'Aruba',
28
- 'ay' => 'Antarctica',
29
- 'azu' => 'Arizona',
30
- 'ba' => 'Bahrain',
31
- 'bb' => 'Barbados',
32
- 'bcc' => 'British Columbia',
33
- 'bd' => 'Burundi',
34
- 'be' => 'Belgium',
35
- 'bf' => 'Bahamas',
36
- 'bg' => 'Bangladesh',
37
- 'bh' => 'Belize',
38
- 'bi' => 'British Indian Ocean Territory',
39
- 'bl' => 'Brazil',
40
- 'bm' => 'Bermuda Islands',
41
- 'bn' => 'Bosnia and Hercegovina',
42
- 'bo' => 'Bolivia',
43
- 'bp' => 'Solomon Islands',
44
- 'br' => 'Burma',
45
- 'bs' => 'Botswana',
46
- 'bt' => 'Bhutan',
47
- 'bu' => 'Bulgaria',
48
- 'bv' => 'Bouvet Island',
49
- 'bw' => 'Belarus',
50
- 'bwr' => 'Byelorussian S.S.R.',
51
- 'bx' => 'Brunei',
52
- 'ca' => 'Caribbean Netherlands',
53
- 'cau' => 'California',
54
- 'cb' => 'Cambodia',
55
- 'cc' => 'China',
56
- 'cd' => 'Chad',
57
- 'ce' => 'Sri Lanka',
58
- 'cf' => 'Congo (Brazzaville)',
59
- 'cg' => 'Congo (Democratic Republic)',
60
- 'ch' => 'China (Republic : 1949- )',
61
- 'ci' => 'Croatia',
62
- 'cj' => 'Cayman Islands',
63
- 'ck' => 'Colombia',
64
- 'cl' => 'Chile',
65
- 'cm' => 'Cameroon',
66
- 'cn' => 'Canada',
67
- 'co' => 'Curaçao',
68
- 'cou' => 'Colorado',
69
- 'cp' => 'Canton and Enderbury Islands',
70
- 'cq' => 'Comoros',
71
- 'cr' => 'Costa Rica',
72
- 'cs' => 'Czechoslovakia',
73
- 'ctu' => 'Connecticut',
74
- 'cu' => 'Cuba',
75
- 'cv' => 'Cape Verde',
76
- 'cw' => 'Cook Islands',
77
- 'cx' => 'Central African Republic',
78
- 'cy' => 'Cyprus',
79
- 'cz' => 'Canal Zone',
80
- 'dcu' => 'District of Columbia',
81
- 'deu' => 'Delaware',
82
- 'dk' => 'Denmark',
83
- 'dm' => 'Benin',
84
- 'dq' => 'Dominica',
85
- 'dr' => 'Dominican Republic',
86
- 'ea' => 'Eritrea',
87
- 'ec' => 'Ecuador',
88
- 'eg' => 'Equatorial Guinea',
89
- 'em' => 'Timor-Leste',
90
- 'enk' => 'England',
91
- 'er' => 'Estonia',
92
- 'err' => 'Estonia',
93
- 'es' => 'El Salvador',
94
- 'et' => 'Ethiopia',
95
- 'fa' => 'Faroe Islands',
96
- 'fg' => 'French Guiana',
97
- 'fi' => 'Finland',
98
- 'fj' => 'Fiji',
99
- 'fk' => 'Falkland Islands',
100
- 'flu' => 'Florida',
101
- 'fm' => 'Micronesia (Federated States)',
102
- 'fp' => 'French Polynesia',
103
- 'fr' => 'France',
104
- 'fs' => 'Terres australes et antarctiques françaises',
105
- 'ft' => 'Djibouti',
106
- 'gau' => 'Georgia',
107
- 'gb' => 'Kiribati',
108
- 'gd' => 'Grenada',
109
- 'ge' => 'Germany (East)',
110
- 'gh' => 'Ghana',
111
- 'gi' => 'Gibraltar',
112
- 'gl' => 'Greenland',
113
- 'gm' => 'Gambia',
114
- 'gn' => 'Gilbert and Ellice Islands',
115
- 'go' => 'Gabon',
116
- 'gp' => 'Guadeloupe',
117
- 'gr' => 'Greece',
118
- 'gs' => 'Georgia (Republic)',
119
- 'gsr' => 'Georgian S.S.R.',
120
- 'gt' => 'Guatemala',
121
- 'gu' => 'Guam',
122
- 'gv' => 'Guinea',
123
- 'gw' => 'Germany',
124
- 'gy' => 'Guyana',
125
- 'gz' => 'Gaza Strip',
126
- 'hiu' => 'Hawaii',
127
- 'hk' => 'Hong Kong',
128
- 'hm' => 'Heard and McDonald Islands',
129
- 'ho' => 'Honduras',
130
- 'ht' => 'Haiti',
131
- 'hu' => 'Hungary',
132
- 'iau' => 'Iowa',
133
- 'ic' => 'Iceland',
134
- 'idu' => 'Idaho',
135
- 'ie' => 'Ireland',
136
- 'ii' => 'India',
137
- 'ilu' => 'Illinois',
138
- 'inu' => 'Indiana',
139
- 'io' => 'Indonesia',
140
- 'iq' => 'Iraq',
141
- 'ir' => 'Iran',
142
- 'is' => 'Israel',
143
- 'it' => 'Italy',
144
- 'iu' => 'Israel-Syria Demilitarized Zones',
145
- 'iv' => "Côte d'Ivoire",
146
- 'iw' => 'Israel-Jordan Demilitarized Zones',
147
- 'iy' => 'Iraq-Saudi Arabia Neutral Zone',
148
- 'ja' => 'Japan',
149
- 'ji' => 'Johnston Atoll',
150
- 'jm' => 'Jamaica',
151
- 'jn' => 'Jan Mayen',
152
- 'jo' => 'Jordan',
153
- 'ke' => 'Kenya',
154
- 'kg' => 'Kyrgyzstan',
155
- 'kgr' => 'Kirghiz S.S.R.',
156
- 'kn' => 'Korea (North)',
157
- 'ko' => 'Korea (South)',
158
- 'ksu' => 'Kansas',
159
- 'ku' => 'Kuwait',
160
- 'kv' => 'Kosovo',
161
- 'kyu' => 'Kentucky',
162
- 'kz' => 'Kazakhstan',
163
- 'kzr' => 'Kazakh S.S.R.',
164
- 'lau' => 'Louisiana',
165
- 'lb' => 'Liberia',
166
- 'le' => 'Lebanon',
167
- 'lh' => 'Liechtenstein',
168
- 'li' => 'Lithuania',
169
- 'lir' => 'Lithuania',
170
- 'ln' => 'Central and Southern Line Islands',
171
- 'lo' => 'Lesotho',
172
- 'ls' => 'Laos',
173
- 'lu' => 'Luxembourg',
174
- 'lv' => 'Latvia',
175
- 'lvr' => 'Latvia',
176
- 'ly' => 'Libya',
177
- 'mau' => 'Massachusetts',
178
- 'mbc' => 'Manitoba',
179
- 'mc' => 'Monaco',
180
- 'mdu' => 'Maryland',
181
- 'meu' => 'Maine',
182
- 'mf' => 'Mauritius',
183
- 'mg' => 'Madagascar',
184
- 'mh' => 'Macao',
185
- 'miu' => 'Michigan',
186
- 'mj' => 'Montserrat',
187
- 'mk' => 'Oman',
188
- 'ml' => 'Mali',
189
- 'mm' => 'Malta',
190
- 'mnu' => 'Minnesota',
191
- 'mo' => 'Montenegro',
192
- 'mou' => 'Missouri',
193
- 'mp' => 'Mongolia',
194
- 'mq' => 'Martinique',
195
- 'mr' => 'Morocco',
196
- 'msu' => 'Mississippi',
197
- 'mtu' => 'Montana',
198
- 'mu' => 'Mauritania',
199
- 'mv' => 'Moldova',
200
- 'mvr' => 'Moldavian S.S.R.',
201
- 'mw' => 'Malawi',
202
- 'mx' => 'Mexico',
203
- 'my' => 'Malaysia',
204
- 'mz' => 'Mozambique',
205
- 'na' => 'Netherlands Antilles',
206
- 'nbu' => 'Nebraska',
207
- 'ncu' => 'North Carolina',
208
- 'ndu' => 'North Dakota',
209
- 'ne' => 'Netherlands',
210
- 'nfc' => 'Newfoundland and Labrador',
211
- 'ng' => 'Niger',
212
- 'nhu' => 'New Hampshire',
213
- 'nik' => 'Northern Ireland',
214
- 'nju' => 'New Jersey',
215
- 'nkc' => 'New Brunswick',
216
- 'nl' => 'New Caledonia',
217
- 'nm' => 'Northern Mariana Islands',
218
- 'nmu' => 'New Mexico',
219
- 'nn' => 'Vanuatu',
220
- 'no' => 'Norway',
221
- 'np' => 'Nepal',
222
- 'nq' => 'Nicaragua',
223
- 'nr' => 'Nigeria',
224
- 'nsc' => 'Nova Scotia',
225
- 'ntc' => 'Northwest Territories',
226
- 'nu' => 'Nauru',
227
- 'nuc' => 'Nunavut',
228
- 'nvu' => 'Nevada',
229
- 'nw' => 'Northern Mariana Islands',
230
- 'nx' => 'Norfolk Island',
231
- 'nyu' => 'New York (State)',
232
- 'nz' => 'New Zealand',
233
- 'ohu' => 'Ohio',
234
- 'oku' => 'Oklahoma',
235
- 'onc' => 'Ontario',
236
- 'oru' => 'Oregon',
237
- 'ot' => 'Mayotte',
238
- 'pau' => 'Pennsylvania',
239
- 'pc' => 'Pitcairn Island',
240
- 'pe' => 'Peru',
241
- 'pf' => 'Paracel Islands',
242
- 'pg' => 'Guinea-Bissau',
243
- 'ph' => 'Philippines',
244
- 'pic' => 'Prince Edward Island',
245
- 'pk' => 'Pakistan',
246
- 'pl' => 'Poland',
247
- 'pn' => 'Panama',
248
- 'po' => 'Portugal',
249
- 'pp' => 'Papua New Guinea',
250
- 'pr' => 'Puerto Rico',
251
- 'pt' => 'Portuguese Timor',
252
- 'pw' => 'Palau',
253
- 'py' => 'Paraguay',
254
- 'qa' => 'Qatar',
255
- 'qea' => 'Queensland',
256
- 'quc' => 'Québec (Province)',
257
- 'rb' => 'Serbia',
258
- 're' => 'Réunion',
259
- 'rh' => 'Zimbabwe',
260
- 'riu' => 'Rhode Island',
261
- 'rm' => 'Romania',
262
- 'ru' => 'Russia (Federation)',
263
- 'rur' => 'Russian S.F.S.R.',
264
- 'rw' => 'Rwanda',
265
- 'ry' => 'Ryukyu Islands, Southern',
266
- 'sa' => 'South Africa',
267
- 'sb' => 'Svalbard',
268
- 'sc' => 'Saint-Barthélemy',
269
- 'scu' => 'South Carolina',
270
- 'sd' => 'South Sudan',
271
- 'sdu' => 'South Dakota',
272
- 'se' => 'Seychelles',
273
- 'sf' => 'Sao Tome and Principe',
274
- 'sg' => 'Senegal',
275
- 'sh' => 'Spanish North Africa',
276
- 'si' => 'Singapore',
277
- 'sj' => 'Sudan',
278
- 'sk' => 'Sikkim',
279
- 'sl' => 'Sierra Leone',
280
- 'sm' => 'San Marino',
281
- 'sn' => 'Sint Maarten',
282
- 'snc' => 'Saskatchewan',
283
- 'so' => 'Somalia',
284
- 'sp' => 'Spain',
285
- 'sq' => 'Swaziland',
286
- 'sr' => 'Surinam',
287
- 'ss' => 'Western Sahara',
288
- 'st' => 'Saint-Martin',
289
- 'stk' => 'Scotland',
290
- 'su' => 'Saudi Arabia',
291
- 'sv' => 'Swan Islands',
292
- 'sw' => 'Sweden',
293
- 'sx' => 'Namibia',
294
- 'sy' => 'Syria',
295
- 'sz' => 'Switzerland',
296
- 'ta' => 'Tajikistan',
297
- 'tar' => 'Tajik S.S.R.',
298
- 'tc' => 'Turks and Caicos Islands',
299
- 'tg' => 'Togo',
300
- 'th' => 'Thailand',
301
- 'ti' => 'Tunisia',
302
- 'tk' => 'Turkmenistan',
303
- 'tkr' => ' Turkmen S.S.R.',
304
- 'tl' => 'Tokelau',
305
- 'tma' => 'Tasmania',
306
- 'tnu' => 'Tennessee',
307
- 'to' => 'Tonga',
308
- 'tr' => 'Trinidad and Tobago',
309
- 'ts' => 'United Arab Emirates',
310
- 'tt' => 'Trust Territory of the Pacific Islands',
311
- 'tu' => 'Turkey',
312
- 'tv' => 'Tuvalu',
313
- 'txu' => 'Texas',
314
- 'tz' => 'Tanzania',
315
- 'ua' => 'Egypt',
316
- 'uc' => 'United States Misc. Caribbean Islands',
317
- 'ug' => 'Uganda',
318
- 'ui' => 'United Kingdom Misc. Islands',
319
- 'uik' => 'United Kingdom Misc. Islands',
320
- 'uk' => 'United Kingdom',
321
- 'un' => 'Ukraine',
322
- 'unr' => 'Ukraine',
323
- 'up' => 'United States Misc. Pacific Islands',
324
- 'ur' => 'Soviet Union',
325
- 'us' => 'United States',
326
- 'utu' => 'Utah',
327
- 'uv' => 'Burkina Faso',
328
- 'uy' => 'Uruguay',
329
- 'uz' => 'Uzbekistan',
330
- 'uzr' => 'Uzbek S.S.R.',
331
- 'vau' => 'Virginia',
332
- 'vb' => 'British Virgin Islands',
333
- 'vc' => 'Vatican City',
334
- 've' => 'Venezuela',
335
- 'vi' => 'Virgin Islands of the United States',
336
- 'vm' => 'Vietnam',
337
- 'vn' => 'Vietnam, North',
338
- 'vp' => 'Various places',
339
- 'vra' => 'Victoria',
340
- 'vs' => 'Vietnam, South',
341
- 'vtu' => 'Vermont',
342
- 'wau' => 'Washington (State)',
343
- 'wb' => 'West Berlin',
344
- 'wea' => 'Western Australia',
345
- 'wf' => 'Wallis and Futuna',
346
- 'wiu' => 'Wisconsin',
347
- 'wj' => 'West Bank of the Jordan River',
348
- 'wk' => 'Wake Island',
349
- 'wlk' => 'Wales',
350
- 'ws' => 'Samoa',
351
- 'wvu' => 'West Virginia',
352
- 'wyu' => 'Wyoming',
353
- 'xa' => 'Christmas Island (Indian Ocean)',
354
- 'xb' => 'Cocos (Keeling) Islands',
355
- 'xc' => 'Maldives',
356
- 'xd' => 'Saint Kitts-Nevis',
357
- 'xe' => 'Marshall Islands',
358
- 'xf' => 'Midway Islands',
359
- 'xga' => 'Coral Sea Islands Territory',
360
- 'xh' => 'Niue',
361
- 'xi' => 'Saint Kitts-Nevis-Anguilla',
362
- 'xj' => 'Saint Helena',
363
- 'xk' => 'Saint Lucia',
364
- 'xl' => 'Saint Pierre and Miquelon',
365
- 'xm' => 'Saint Vincent and the Grenadines',
366
- 'xn' => 'Macedonia',
367
- 'xna' => 'New South Wales',
368
- 'xo' => 'Slovakia',
369
- 'xoa' => 'Northern Territory',
370
- 'xp' => 'Spratly Island',
371
- 'xr' => 'Czech Republic',
372
- 'xra' => 'South Australia',
373
- 'xs' => 'South Georgia and the South Sandwich Islands',
374
- 'xv' => 'Slovenia',
375
- # Removing per METADOR-32
376
- # "xx" => "No place, unknown, or undetermined",
377
- 'xxc' => 'Canada',
378
- 'xxk' => 'United Kingdom',
379
- 'xxr' => 'Soviet Union',
380
- 'xxu' => 'United States',
381
- 'ye' => 'Yemen',
382
- 'ykc' => 'Yukon Territory',
383
- 'ys' => "Yemen (People's Democratic Republic)",
384
- 'yu' => 'Serbia and Montenegro',
385
- 'za' => 'Zambia' }
8
+ @country_codes ||= MARC_COUNTRY.except('xx') # Removing per METADOR-32
386
9
  end
387
10
  end
388
11
  end
@@ -29,8 +29,8 @@ module ModsDisplay
29
29
  end
30
30
 
31
31
  def resource_type_is_collection?(value)
32
- return unless value.respond_to?(:typeOfResource)
33
- return unless value.typeOfResource.attributes.length.positive?
32
+ return false unless value.respond_to?(:typeOfResource)
33
+ return false unless value.typeOfResource.attributes.length.positive?
34
34
 
35
35
  value.typeOfResource.attributes.length.positive? &&
36
36
  value.typeOfResource.attributes.first.key?('collection') &&
@@ -12,9 +12,7 @@ module ModsDisplay
12
12
  private
13
13
 
14
14
  def identifier_label(element)
15
- if element.attributes['type'].respond_to?(:value)
16
- return identifier_labels[element.attributes['type'].value] || "#{element.attributes['type'].value}:"
17
- end
15
+ return identifier_labels[element.attributes['type'].value] || "#{element.attributes['type'].value}:" if element.attributes['type'].respond_to?(:value)
18
16
 
19
17
  I18n.t('mods_display.identifier')
20
18
  end
@@ -10,7 +10,8 @@ module ModsDisplay
10
10
 
11
11
  if child.name.to_sym == :url
12
12
  loc_label = displayLabel(location) || I18n.t('mods_display.location')
13
- value = "<a href='#{element_text(child)}'>#{(displayLabel(child) || element_text(child)).gsub(/:$/, '')}</a>"
13
+ value = "<a href='#{element_text(child)}'>#{(displayLabel(child) || element_text(child)).gsub(/:$/,
14
+ '')}</a>"
14
15
  else
15
16
  loc_label = location_label(child) || displayLabel(location) || I18n.t('mods_display.location')
16
17
  value = element_text(child)
@@ -5,10 +5,11 @@ module ModsDisplay
5
5
  include ModsDisplay::RelatorCodes
6
6
  def fields
7
7
  return_fields = @values.map do |value|
8
+ name_identifiers = value.element_children.select { |child| child.name == 'nameIdentifier' }
8
9
  person = if value.displayForm.length.positive?
9
- ModsDisplay::Name::Person.new(name: element_text(value.displayForm))
10
+ ModsDisplay::Name::Person.new(name: element_text(value.displayForm), name_identifiers: name_identifiers)
10
11
  elsif !name_parts(value).empty?
11
- ModsDisplay::Name::Person.new(name: name_parts(value))
12
+ ModsDisplay::Name::Person.new(name: name_parts(value), name_identifiers: name_identifiers)
12
13
  end
13
14
  # The person may have multiple roles, so we have to divide them up into an array
14
15
  role_labels(value).collect do |role_label|
@@ -163,7 +164,7 @@ module ModsDisplay
163
164
  # Build the new fields data, stripping out the roles within the Person classes
164
165
  label_keys.uniq.map do |k|
165
166
  values = results[k].map do |person|
166
- ModsDisplay::Name::Person.new(name: person.name)
167
+ ModsDisplay::Name::Person.new(name: person.name, orcid: person.orcid)
167
168
  end
168
169
 
169
170
  ModsDisplay::Values.new(label: k, values: values)
@@ -171,15 +172,29 @@ module ModsDisplay
171
172
  end
172
173
 
173
174
  class Person
174
- attr_accessor :name
175
+ attr_accessor :name, :orcid
175
176
 
176
177
  def initialize(data)
177
178
  @name = data[:name]
179
+ @orcid = if data[:orcid].present?
180
+ data[:orcid]
181
+ elsif data[:name_identifiers].present?
182
+ orcid_identifier(data[:name_identifiers])
183
+ end
178
184
  end
179
185
 
180
186
  def to_s
181
187
  @name
182
188
  end
189
+
190
+ private
191
+
192
+ def orcid_identifier(name_identifiers)
193
+ orcid = name_identifiers.select do |name_identifier|
194
+ name_identifier.attribute('type')&.value == 'orcid'
195
+ end
196
+ orcid.first&.text
197
+ end
183
198
  end
184
199
  end
185
200
  end
@@ -4,7 +4,8 @@ module ModsDisplay
4
4
  class Note < Field
5
5
  def fields
6
6
  return_fields = note_fields.map do |value|
7
- ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)], field: self)
7
+ ModsDisplay::Values.new(label: displayLabel(value) || note_label(value), values: [element_text(value)],
8
+ field: self)
8
9
  end
9
10
  collapse_fields(return_fields)
10
11
  end
@@ -24,9 +25,7 @@ module ModsDisplay
24
25
  end
25
26
 
26
27
  def note_label(element)
27
- if element.attributes['type'].respond_to?(:value)
28
- return note_labels[element.attributes['type'].value] || "#{element.attributes['type'].value.capitalize}:"
29
- end
28
+ return note_labels[element.attributes['type'].value] || "#{element.attributes['type'].value.capitalize}:" if element.attributes['type'].respond_to?(:value)
30
29
 
31
30
  I18n.t('mods_display.note')
32
31
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
- module RelatorCodes
5
- def relator_codes
4
+ module RelatorCodes # rubocop:disable Metrics/ModuleLength
5
+ def relator_codes # rubocop:disable Metrics/MethodLength
6
6
  { 'abr' => 'Abridger',
7
7
  'acp' => 'Art copyist',
8
8
  'act' => 'Actor',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ModsDisplay
4
- VERSION = '1.3.1'
4
+ VERSION = '1.3.2'
5
5
  end
data/mods_display.gemspec CHANGED
@@ -21,9 +21,10 @@ 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', '~> 3.3'
24
+ gem.add_dependency 'stanford-mods', '~> 3.3', '>=3.3.7' # require stanford-mods 3.3.7 for orcid support
25
25
  gem.add_dependency 'i18n'
26
26
  gem.add_dependency 'view_component'
27
+ gem.add_dependency 'rails_autolink'
27
28
 
28
29
  gem.add_development_dependency 'rake'
29
30
  gem.add_development_dependency 'rspec', '~> 3.0'
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.1
4
+ version: 1.3.2
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-04-05 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.3.7
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.7
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: i18n
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +58,20 @@ dependencies:
52
58
  - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rails_autolink
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -225,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
245
  - !ruby/object:Gem::Version
226
246
  version: '0'
227
247
  requirements: []
228
- rubygems_version: 3.4.6
248
+ rubygems_version: 3.4.13
229
249
  signing_key:
230
250
  specification_version: 4
231
251
  summary: The MODS Display gem allows implementers to configure a customized display