briard 2.4.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/codeql-analysis.yml +72 -0
  3. data/.github/workflows/rubocop.yml +50 -0
  4. data/.rubocop.yml +144 -620
  5. data/.rubocop_todo.yml +76 -0
  6. data/CHANGELOG.md +18 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +40 -6
  9. data/Rakefile +1 -1
  10. data/{bolognese.gemspec → briard.gemspec} +46 -39
  11. data/lib/briard/array.rb +2 -2
  12. data/lib/briard/author_utils.rb +79 -71
  13. data/lib/briard/cli.rb +12 -13
  14. data/lib/briard/crossref_utils.rb +73 -61
  15. data/lib/briard/datacite_utils.rb +132 -106
  16. data/lib/briard/doi_utils.rb +10 -10
  17. data/lib/briard/metadata.rb +96 -106
  18. data/lib/briard/metadata_utils.rb +87 -78
  19. data/lib/briard/readers/bibtex_reader.rb +65 -65
  20. data/lib/briard/readers/cff_reader.rb +88 -70
  21. data/lib/briard/readers/citeproc_reader.rb +90 -84
  22. data/lib/briard/readers/codemeta_reader.rb +68 -50
  23. data/lib/briard/readers/crosscite_reader.rb +2 -2
  24. data/lib/briard/readers/crossref_reader.rb +249 -210
  25. data/lib/briard/readers/datacite_json_reader.rb +3 -3
  26. data/lib/briard/readers/datacite_reader.rb +225 -189
  27. data/lib/briard/readers/npm_reader.rb +49 -42
  28. data/lib/briard/readers/ris_reader.rb +82 -80
  29. data/lib/briard/readers/schema_org_reader.rb +182 -159
  30. data/lib/briard/string.rb +1 -1
  31. data/lib/briard/utils.rb +4 -4
  32. data/lib/briard/version.rb +3 -1
  33. data/lib/briard/whitelist_scrubber.rb +11 -4
  34. data/lib/briard/writers/bibtex_writer.rb +14 -8
  35. data/lib/briard/writers/cff_writer.rb +33 -26
  36. data/lib/briard/writers/codemeta_writer.rb +19 -15
  37. data/lib/briard/writers/csv_writer.rb +6 -4
  38. data/lib/briard/writers/datacite_json_writer.rb +8 -2
  39. data/lib/briard/writers/jats_writer.rb +33 -28
  40. data/lib/briard/writers/rdf_xml_writer.rb +1 -1
  41. data/lib/briard/writers/ris_writer.rb +30 -18
  42. data/lib/briard/writers/turtle_writer.rb +1 -1
  43. data/lib/briard.rb +6 -6
  44. data/rubocop.sarif +0 -0
  45. data/spec/array_spec.rb +5 -5
  46. data/spec/author_utils_spec.rb +151 -132
  47. data/spec/datacite_utils_spec.rb +135 -83
  48. data/spec/doi_utils_spec.rb +168 -164
  49. data/spec/find_from_format_spec.rb +69 -69
  50. data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/onlies_keep_specific_tags.yml +65 -0
  51. data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/removes_a_tags.yml +65 -0
  52. data/spec/metadata_spec.rb +91 -90
  53. data/spec/readers/bibtex_reader_spec.rb +43 -38
  54. data/spec/readers/cff_reader_spec.rb +165 -153
  55. data/spec/readers/citeproc_reader_spec.rb +45 -40
  56. data/spec/readers/codemeta_reader_spec.rb +128 -115
  57. data/spec/readers/crosscite_reader_spec.rb +34 -24
  58. data/spec/readers/crossref_reader_spec.rb +1098 -939
  59. data/spec/readers/datacite_json_reader_spec.rb +53 -40
  60. data/spec/readers/datacite_reader_spec.rb +1541 -1337
  61. data/spec/readers/npm_reader_spec.rb +48 -43
  62. data/spec/readers/ris_reader_spec.rb +53 -47
  63. data/spec/readers/schema_org_reader_spec.rb +329 -267
  64. data/spec/spec_helper.rb +6 -5
  65. data/spec/utils_spec.rb +371 -347
  66. data/spec/writers/bibtex_writer_spec.rb +143 -143
  67. data/spec/writers/cff_writer_spec.rb +96 -90
  68. data/spec/writers/citation_writer_spec.rb +34 -33
  69. data/spec/writers/citeproc_writer_spec.rb +226 -224
  70. data/spec/writers/codemeta_writer_spec.rb +18 -16
  71. data/spec/writers/crosscite_writer_spec.rb +91 -73
  72. data/spec/writers/crossref_writer_spec.rb +99 -91
  73. data/spec/writers/csv_writer_spec.rb +70 -70
  74. data/spec/writers/datacite_json_writer_spec.rb +78 -68
  75. data/spec/writers/datacite_writer_spec.rb +417 -322
  76. data/spec/writers/jats_writer_spec.rb +177 -161
  77. data/spec/writers/rdf_xml_writer_spec.rb +68 -63
  78. data/spec/writers/ris_writer_spec.rb +162 -162
  79. data/spec/writers/turtle_writer_spec.rb +47 -47
  80. metadata +242 -166
  81. data/.github/workflows/release.yml +0 -47
@@ -3,7 +3,7 @@
3
3
  module Briard
4
4
  module DataciteUtils
5
5
  def datacite_xml
6
- @datacite_xml ||= Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
6
+ @datacite_xml ||= Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
7
7
  xml.resource(root_attributes) do
8
8
  insert_work(xml)
9
9
  end
@@ -13,17 +13,21 @@ module Briard
13
13
  def datacite_errors(xml: nil, schema_version: nil)
14
14
  if xml.present?
15
15
  namespaces = Nokogiri::XML(xml, nil, 'UTF-8').root.namespaces
16
- schema_version = namespaces.fetch('xmlns',nil).presence || namespaces.fetch('xmlns:ns0',nil).presence
16
+ schema_version = namespaces.fetch('xmlns',
17
+ nil).presence || namespaces.fetch('xmlns:ns0',
18
+ nil).presence
17
19
  end
18
-
20
+
19
21
  # handle crossref namespace
20
- schema_version = schema_version.to_s.start_with?("http://datacite.org/schema/kernel") ? schema_version : "http://datacite.org/schema/kernel-4"
22
+ unless schema_version.to_s.start_with?('http://datacite.org/schema/kernel')
23
+ schema_version = 'http://datacite.org/schema/kernel-4'
24
+ end
21
25
 
22
- kernel = schema_version.to_s.split("/").last
26
+ kernel = schema_version.to_s.split('/').last
23
27
  filepath = File.expand_path("../../../resources/#{kernel}/metadata.xsd", __FILE__)
24
28
  schema = Nokogiri::XML::Schema(open(filepath))
25
29
 
26
- schema.validate(Nokogiri::XML(xml, nil, 'UTF-8')).map { |error| error.to_s }.unwrap
30
+ schema.validate(Nokogiri::XML(xml, nil, 'UTF-8')).map(&:to_s).unwrap
27
31
  rescue Nokogiri::XML::SyntaxError => e
28
32
  e.message
29
33
  end
@@ -52,14 +56,14 @@ module Briard
52
56
  end
53
57
 
54
58
  def insert_identifier(xml)
55
- xml.identifier(doi, 'identifierType' => "DOI")
59
+ xml.identifier(doi, 'identifierType' => 'DOI')
56
60
  end
57
61
 
58
62
  def insert_creators(xml)
59
63
  xml.creators do
60
64
  Array.wrap(creators).each do |au|
61
65
  xml.creator do
62
- insert_person(xml, au, "creator")
66
+ insert_person(xml, au, 'creator')
63
67
  end
64
68
  end
65
69
  end
@@ -70,25 +74,31 @@ module Briard
70
74
 
71
75
  xml.contributors do
72
76
  Array.wrap(contributors).each do |con|
73
- xml.contributor("contributorType" => con["contributorType"] || "Other") do
74
- insert_person(xml, con, "contributor")
77
+ xml.contributor('contributorType' => con['contributorType'] || 'Other') do
78
+ insert_person(xml, con, 'contributor')
75
79
  end
76
80
  end
77
81
  end
78
82
  end
79
83
 
80
84
  def insert_person(xml, person, type)
81
- person_name = person["familyName"].present? ? [person["familyName"], person["givenName"]].compact.join(", ") : person["name"]
82
- attributes = { "nameType" => person["nameType"] }.compact
83
- xml.send(type + "Name", person_name, attributes)
84
- xml.givenName(person["givenName"]) if person["givenName"].present?
85
- xml.familyName(person["familyName"]) if person["familyName"].present?
86
- Array.wrap(person["nameIdentifiers"]).each do |ni|
87
- xml.nameIdentifier(ni["nameIdentifier"], 'nameIdentifierScheme' => ni["nameIdentifierScheme"], 'schemeURI' => ni["schemeUri"])
85
+ person_name = if person['familyName'].present?
86
+ [person['familyName'], person['givenName']].compact.join(', ')
87
+ else
88
+ person['name']
89
+ end
90
+ attributes = { 'nameType' => person['nameType'] }.compact
91
+ xml.send("#{type}Name", person_name, attributes)
92
+ xml.givenName(person['givenName']) if person['givenName'].present?
93
+ xml.familyName(person['familyName']) if person['familyName'].present?
94
+ Array.wrap(person['nameIdentifiers']).each do |ni|
95
+ xml.nameIdentifier(ni['nameIdentifier'],
96
+ 'nameIdentifierScheme' => ni['nameIdentifierScheme'], 'schemeURI' => ni['schemeUri'])
88
97
  end
89
- Array.wrap(person["affiliation"]).each do |affiliation|
90
- attributes = { "affiliationIdentifier" => affiliation["affiliationIdentifier"], "affiliationIdentifierScheme" => affiliation["affiliationIdentifierScheme"], "schemeURI" => affiliation["schemeUri"] }.compact
91
- xml.affiliation(affiliation["name"], attributes)
98
+ Array.wrap(person['affiliation']).each do |affiliation|
99
+ attributes = { 'affiliationIdentifier' => affiliation['affiliationIdentifier'],
100
+ 'affiliationIdentifierScheme' => affiliation['affiliationIdentifierScheme'], 'schemeURI' => affiliation['schemeUri'] }.compact
101
+ xml.affiliation(affiliation['name'], attributes)
92
102
  end
93
103
  end
94
104
 
@@ -99,17 +109,17 @@ module Briard
99
109
  t = title
100
110
  else
101
111
  t = {}
102
- t["title"] = title
112
+ t['title'] = title
103
113
  end
104
114
 
105
- attributes = { 'titleType' => t["titleType"], 'xml:lang' => t["lang"] }.compact
106
- xml.title(t["title"], attributes)
115
+ attributes = { 'titleType' => t['titleType'], 'xml:lang' => t['lang'] }.compact
116
+ xml.title(t['title'], attributes)
107
117
  end
108
118
  end
109
119
  end
110
120
 
111
121
  def insert_publisher(xml)
112
- xml.publisher(publisher || container && container["title"])
122
+ xml.publisher(publisher || (container && container['title']))
113
123
  end
114
124
 
115
125
  def insert_publication_year(xml)
@@ -117,19 +127,22 @@ module Briard
117
127
  end
118
128
 
119
129
  def insert_resource_type(xml)
120
- return xml unless types.is_a?(Hash) && (types["schemaOrg"].present? || types["resourceTypeGeneral"])
130
+ unless types.is_a?(Hash) && (types['schemaOrg'].present? || types['resourceTypeGeneral'])
131
+ return xml
132
+ end
121
133
 
122
- xml.resourceType(types["resourceType"] || types["schemaOrg"],
123
- 'resourceTypeGeneral' => types["resourceTypeGeneral"] || Metadata::SO_TO_DC_TRANSLATIONS[types["schemaOrg"]] || "Other")
134
+ xml.resourceType(types['resourceType'] || types['schemaOrg'],
135
+ 'resourceTypeGeneral' => types['resourceTypeGeneral'] || Metadata::SO_TO_DC_TRANSLATIONS[types['schemaOrg']] || 'Other')
124
136
  end
125
137
 
126
138
  def insert_alternate_identifiers(xml)
127
- alternate_identifiers = Array.wrap(identifiers).select { |r| r["identifierType"] != "DOI" }
139
+ alternate_identifiers = Array.wrap(identifiers).reject { |r| r['identifierType'] == 'DOI' }
128
140
  return xml unless alternate_identifiers.present?
129
141
 
130
142
  xml.alternateIdentifiers do
131
143
  Array.wrap(alternate_identifiers).each do |alternate_identifier|
132
- xml.alternateIdentifier(alternate_identifier["identifier"], 'alternateIdentifierType' => alternate_identifier["identifierType"])
144
+ xml.alternateIdentifier(alternate_identifier['identifier'],
145
+ 'alternateIdentifierType' => alternate_identifier['identifierType'])
133
146
  end
134
147
  end
135
148
  end
@@ -139,8 +152,9 @@ module Briard
139
152
 
140
153
  xml.dates do
141
154
  Array.wrap(dates).each do |date|
142
- attributes = { 'dateType' => date["dateType"] || "Issued", 'dateInformation' => date["dateInformation"] }.compact
143
- xml.date(date["date"], attributes)
155
+ attributes = { 'dateType' => date['dateType'] || 'Issued',
156
+ 'dateInformation' => date['dateInformation'] }.compact
157
+ xml.date(date['date'], attributes)
144
158
  end
145
159
  end
146
160
  end
@@ -151,10 +165,18 @@ module Briard
151
165
  xml.fundingReferences do
152
166
  Array.wrap(funding_references).each do |funding_reference|
153
167
  xml.fundingReference do
154
- xml.funderName(funding_reference["funderName"])
155
- xml.funderIdentifier(funding_reference["funderIdentifier"], { "funderIdentifierType" => funding_reference["funderIdentifierType"] }.compact) if funding_reference["funderIdentifier"].present?
156
- xml.awardNumber(funding_reference["awardNumber"], { "awardURI" => funding_reference["awardUri"] }.compact) if funding_reference["awardNumber"].present? || funding_reference["awardUri"].present?
157
- xml.awardTitle(funding_reference["awardTitle"]) if funding_reference["awardTitle"].present?
168
+ xml.funderName(funding_reference['funderName'])
169
+ if funding_reference['funderIdentifier'].present?
170
+ xml.funderIdentifier(funding_reference['funderIdentifier'],
171
+ { 'funderIdentifierType' => funding_reference['funderIdentifierType'] }.compact)
172
+ end
173
+ if funding_reference['awardNumber'].present? || funding_reference['awardUri'].present?
174
+ xml.awardNumber(funding_reference['awardNumber'],
175
+ { 'awardURI' => funding_reference['awardUri'] }.compact)
176
+ end
177
+ if funding_reference['awardTitle'].present?
178
+ xml.awardTitle(funding_reference['awardTitle'])
179
+ end
158
180
  end
159
181
  end
160
182
  end
@@ -169,12 +191,13 @@ module Briard
169
191
  s = subject
170
192
  else
171
193
  s = {}
172
- s["subject"] = subject
194
+ s['subject'] = subject
173
195
  end
174
196
 
175
- attributes = { "subjectScheme" => s["subjectScheme"], "schemeURI" => s["schemeUri"], "valueURI" => s["valueUri"], "xml:lang" => s["lang"] }.compact
197
+ attributes = { 'subjectScheme' => s['subjectScheme'], 'schemeURI' => s['schemeUri'],
198
+ 'valueURI' => s['valueUri'], 'xml:lang' => s['lang'] }.compact
176
199
 
177
- xml.subject(s["subject"], attributes)
200
+ xml.subject(s['subject'], attributes)
178
201
  end
179
202
  end
180
203
  end
@@ -185,7 +208,6 @@ module Briard
185
208
  xml.version(version_info)
186
209
  end
187
210
 
188
-
189
211
  def insert_language(xml)
190
212
  return xml unless language.present?
191
213
 
@@ -198,15 +220,18 @@ module Briard
198
220
  xml.relatedIdentifiers do
199
221
  related_identifiers.each do |related_identifier|
200
222
  attributes = {
201
- 'relatedIdentifierType' => related_identifier["relatedIdentifierType"],
202
- 'relationType' => related_identifier["relationType"],
203
- 'resourceTypeGeneral' => related_identifier["resourceTypeGeneral"] }.compact
223
+ 'relatedIdentifierType' => related_identifier['relatedIdentifierType'],
224
+ 'relationType' => related_identifier['relationType'],
225
+ 'resourceTypeGeneral' => related_identifier['resourceTypeGeneral']
226
+ }.compact
204
227
 
205
- attributes.merge({ 'relatedMetadataScheme' => related_identifier["relatedMetadataSchema"],
206
- 'schemeURI' => related_identifier["schemeUri"],
207
- 'schemeType' => related_identifier["schemeType"]}.compact) if %w(HasMetadata IsMetadataFor).include?(related_identifier["relationType"])
228
+ if %w[HasMetadata IsMetadataFor].include?(related_identifier['relationType'])
229
+ attributes.merge({ 'relatedMetadataScheme' => related_identifier['relatedMetadataSchema'],
230
+ 'schemeURI' => related_identifier['schemeUri'],
231
+ 'schemeType' => related_identifier['schemeType'] }.compact)
232
+ end
208
233
 
209
- xml.relatedIdentifier(related_identifier["relatedIdentifier"], attributes)
234
+ xml.relatedIdentifier(related_identifier['relatedIdentifier'], attributes)
210
235
  end
211
236
  end
212
237
  end
@@ -217,25 +242,23 @@ module Briard
217
242
  xml.relatedItems do
218
243
  related_items.each do |related_item|
219
244
  attributes = {
220
- 'relatedItemType' => related_item["relatedItemType"],
221
- 'relationType' => related_item["relationType"],
245
+ 'relatedItemType' => related_item['relatedItemType'],
246
+ 'relationType' => related_item['relationType']
222
247
  }.compact
223
248
 
224
- xml.relatedItem(related_item["relatedItem"], attributes) do
225
-
226
- xml.relatedItemIdentifier(related_item["relatedItemIdentifier"]['relatedItemIdentifier'],
227
- {
228
- 'relatedItemIdentifierType' => related_item["relatedItemIdentifier"]["relatedItemIdentifierType"],
229
- 'relatedMetadataScheme' => related_item["relatedItemIdentifier"]["relatedMetadataScheme"],
230
- 'schemeURI' => related_item["relatedItemIdentifier"]["schemeURI"],
231
- 'schemeType' => related_item["relatedItemIdentifier"]["schemeType"],
232
- }.compact
233
- )
249
+ xml.relatedItem(related_item['relatedItem'], attributes) do
250
+ xml.relatedItemIdentifier(related_item['relatedItemIdentifier']['relatedItemIdentifier'],
251
+ {
252
+ 'relatedItemIdentifierType' => related_item['relatedItemIdentifier']['relatedItemIdentifierType'],
253
+ 'relatedMetadataScheme' => related_item['relatedItemIdentifier']['relatedMetadataScheme'],
254
+ 'schemeURI' => related_item['relatedItemIdentifier']['schemeURI'],
255
+ 'schemeType' => related_item['relatedItemIdentifier']['schemeType']
256
+ }.compact)
234
257
 
235
258
  xml.creators do
236
259
  Array.wrap(related_item['creators']).each do |au|
237
260
  xml.creator do
238
- insert_person(xml, au, "creator")
261
+ insert_person(xml, au, 'creator')
239
262
  end
240
263
  end
241
264
  end
@@ -246,31 +269,31 @@ module Briard
246
269
  t = title
247
270
  else
248
271
  t = {}
249
- t["title"] = title
272
+ t['title'] = title
250
273
  end
251
274
 
252
- attributes = { 'titleType' => t["titleType"], 'xml:lang' => t["lang"] }.compact
253
- xml.title(t["title"], attributes)
275
+ attributes = { 'titleType' => t['titleType'], 'xml:lang' => t['lang'] }.compact
276
+ xml.title(t['title'], attributes)
254
277
  end
255
278
  end
256
279
 
257
280
  xml.publicationYear(related_item['publicationYear'])
258
281
  xml.volume(related_item['volume'])
259
282
  xml.issue(related_item['issue'])
260
- xml.number(related_item['number'], {'numberType' => related_item['numberType']}.compact)
283
+ xml.number(related_item['number'],
284
+ { 'numberType' => related_item['numberType'] }.compact)
261
285
  xml.firstPage(related_item['firstPage'])
262
286
  xml.lastPage(related_item['lastPage'])
263
287
  xml.publisher(related_item['publisher'])
264
288
  xml.edition(related_item['edition'])
265
289
 
266
290
  xml.contributors do
267
- Array.wrap(related_item["contributors"]).each do |con|
268
- xml.contributor("contributorType" => con["contributorType"] || "Other") do
269
- insert_person(xml, con, "contributor")
291
+ Array.wrap(related_item['contributors']).each do |con|
292
+ xml.contributor('contributorType' => con['contributorType'] || 'Other') do
293
+ insert_person(xml, con, 'contributor')
270
294
  end
271
295
  end
272
296
  end
273
-
274
297
  end
275
298
  end
276
299
  end
@@ -301,33 +324,35 @@ module Briard
301
324
  r = rights
302
325
  else
303
326
  r = {}
304
- r["rights"] = rights
305
- r["rightsUri"] = normalize_id(rights)
327
+ r['rights'] = rights
328
+ r['rightsUri'] = normalize_id(rights)
306
329
  end
307
330
 
308
331
  attributes = {
309
- "rightsURI" => r["rightsUri"],
310
- "rightsIdentifier" => r["rightsIdentifier"],
311
- "rightsIdentifierScheme" => r["rightsIdentifierScheme"],
312
- "schemeURI" => r["schemeUri"],
313
- "xml:lang" => r["lang"]
332
+ 'rightsURI' => r['rightsUri'],
333
+ 'rightsIdentifier' => r['rightsIdentifier'],
334
+ 'rightsIdentifierScheme' => r['rightsIdentifierScheme'],
335
+ 'schemeURI' => r['schemeUri'],
336
+ 'xml:lang' => r['lang']
314
337
  }.compact
315
338
 
316
- xml.rights(r["rights"], attributes)
339
+ xml.rights(r['rights'], attributes)
317
340
  end
318
341
  end
319
342
  end
320
343
 
321
344
  def insert_descriptions(xml)
322
- return xml unless descriptions.present? || container && container["title"].present?
345
+ return xml unless descriptions.present? || (container && container['title'].present?)
323
346
 
324
347
  xml.descriptions do
325
- if container && container["title"].present?
326
- issue = container["issue"].present? ? "(#{container["issue"]})" : nil
327
- volume_issue = container["volume"].present? ? [container["volume"], issue].join("") : nil
328
- pages = [container["firstPage"], container["lastPage"]].compact.join("-") if container["firstPage"].present?
329
- series_information = [container["title"], volume_issue, pages].compact.join(", ")
330
- xml.description(series_information, 'descriptionType' => "SeriesInformation")
348
+ if container && container['title'].present?
349
+ issue = container['issue'].present? ? "(#{container['issue']})" : nil
350
+ volume_issue = container['volume'].present? ? [container['volume'], issue].join : nil
351
+ if container['firstPage'].present?
352
+ pages = [container['firstPage'], container['lastPage']].compact.join('-')
353
+ end
354
+ series_information = [container['title'], volume_issue, pages].compact.join(', ')
355
+ xml.description(series_information, 'descriptionType' => 'SeriesInformation')
331
356
  end
332
357
 
333
358
  Array.wrap(descriptions).each do |description|
@@ -335,13 +360,14 @@ module Briard
335
360
  d = description
336
361
  else
337
362
  d = {}
338
- d["description"] = description
339
- d["descriptionType"] = "Abstract"
363
+ d['description'] = description
364
+ d['descriptionType'] = 'Abstract'
340
365
  end
341
366
 
342
- attributes = { 'xml:lang' => d["lang"], 'descriptionType' => d["descriptionType"] || "Abstract" }.compact
367
+ attributes = { 'xml:lang' => d['lang'],
368
+ 'descriptionType' => d['descriptionType'] || 'Abstract' }.compact
343
369
 
344
- xml.description(d["description"], attributes)
370
+ xml.description(d['description'], attributes)
345
371
  end
346
372
  end
347
373
  end
@@ -352,31 +378,31 @@ module Briard
352
378
  xml.geoLocations do
353
379
  geo_locations.each do |geo_location|
354
380
  xml.geoLocation do
355
- xml.geoLocationPlace(geo_location["geoLocationPlace"]) if geo_location["geoLocationPlace"]
381
+ if geo_location['geoLocationPlace']
382
+ xml.geoLocationPlace(geo_location['geoLocationPlace'])
383
+ end
356
384
 
357
- if geo_location["geoLocationPoint"]
385
+ if geo_location['geoLocationPoint']
358
386
  xml.geoLocationPoint do
359
- xml.pointLatitude(geo_location.dig("geoLocationPoint", "pointLatitude"))
360
- xml.pointLongitude(geo_location.dig("geoLocationPoint", "pointLongitude"))
387
+ xml.pointLatitude(geo_location.dig('geoLocationPoint', 'pointLatitude'))
388
+ xml.pointLongitude(geo_location.dig('geoLocationPoint', 'pointLongitude'))
361
389
  end
362
390
  end
363
391
 
364
- if geo_location["geoLocationBox"]
392
+ if geo_location['geoLocationBox']
365
393
  xml.geoLocationBox do
366
- xml.westBoundLongitude(geo_location.dig("geoLocationBox", "westBoundLongitude"))
367
- xml.eastBoundLongitude(geo_location.dig("geoLocationBox", "eastBoundLongitude"))
368
- xml.southBoundLatitude(geo_location.dig("geoLocationBox", "southBoundLatitude"))
369
- xml.northBoundLatitude(geo_location.dig("geoLocationBox", "northBoundLatitude"))
394
+ xml.westBoundLongitude(geo_location.dig('geoLocationBox', 'westBoundLongitude'))
395
+ xml.eastBoundLongitude(geo_location.dig('geoLocationBox', 'eastBoundLongitude'))
396
+ xml.southBoundLatitude(geo_location.dig('geoLocationBox', 'southBoundLatitude'))
397
+ xml.northBoundLatitude(geo_location.dig('geoLocationBox', 'northBoundLatitude'))
370
398
  end
371
399
  end
372
- if geo_location["geoLocationPolygon"]
373
- geo_location["geoLocationPolygon"].each do |geo_location_polygon|
374
- xml.geoLocationPolygon do
375
- geo_location_polygon.each do |polygon_point|
376
- xml.polygonPoint do
377
- xml.pointLatitude(polygon_point.dig("polygonPoint", "pointLatitude"))
378
- xml.pointLongitude(polygon_point.dig("polygonPoint", "pointLongitude"))
379
- end
400
+ geo_location['geoLocationPolygon']&.each do |geo_location_polygon|
401
+ xml.geoLocationPolygon do
402
+ geo_location_polygon.each do |polygon_point|
403
+ xml.polygonPoint do
404
+ xml.pointLatitude(polygon_point.dig('polygonPoint', 'pointLatitude'))
405
+ xml.pointLongitude(polygon_point.dig('polygonPoint', 'pointLongitude'))
380
406
  end
381
407
  end
382
408
  end
@@ -387,9 +413,9 @@ module Briard
387
413
  end
388
414
 
389
415
  def root_attributes
390
- { :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
391
- :'xsi:schemaLocation' => 'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd',
392
- :'xmlns' => 'http://datacite.org/schema/kernel-4' }
416
+ { 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
417
+ 'xsi:schemaLocation': 'http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd',
418
+ xmlns: 'http://datacite.org/schema/kernel-4' }
393
419
  end
394
420
  end
395
421
  end
@@ -3,13 +3,13 @@
3
3
  module Briard
4
4
  module DoiUtils
5
5
  def validate_doi(doi)
6
- doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(doi)).last
6
+ doi = Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match(doi)).last
7
7
  # remove non-printing whitespace and downcase
8
8
  doi.delete("\u200B").downcase if doi.present?
9
9
  end
10
10
 
11
11
  def validate_funder_doi(doi)
12
- doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.13039\/)?([1-9]\d+)\z/.match(doi)).last
12
+ doi = Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.13039/)?([1-9]\d+)\z}.match(doi)).last
13
13
 
14
14
  # remove non-printing whitespace and downcase
15
15
  if doi.present?
@@ -19,17 +19,17 @@ module Briard
19
19
  end
20
20
 
21
21
  def validate_prefix(doi)
22
- Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}).*\z/.match(doi)).last
22
+ Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}).*\z}.match(doi)).last
23
23
  end
24
24
 
25
25
  def doi_resolver(doi, options = {})
26
- sandbox = Array(/handle.stage.datacite.org/.match(doi)).last
27
- sandbox.present? || options[:sandbox] ? "https://handle.stage.datacite.org/" : "https://doi.org/"
26
+ sandbox = Array(/handle\.stage\.datacite\.org/.match(doi)).last
27
+ sandbox.present? || options[:sandbox] ? 'https://handle.stage.datacite.org/' : 'https://doi.org/'
28
28
  end
29
29
 
30
30
  def doi_api_url(doi, options = {})
31
- sandbox = Array(/handle.stage.datacite.org/.match(doi)).last
32
- sandbox.present? || options[:sandbox] ? "https://api.stage.datacite.org/dois/#{doi_from_url(doi)}?include=media,client" : "https://api.datacite.org/dois/#{doi_from_url(doi)}?include=media,client"
31
+ sandbox = Array(/handle\.stage\.datacite.\org/.match(doi)).last
32
+ sandbox.present? || options[:sandbox] ? "https://api.stage.datacite.org/dois/#{doi_from_url(doi)}?include=media,client" : "https://api.datacite.org/dois/#{doi_from_url(doi)}?include=media,client"
33
33
  end
34
34
 
35
35
  def normalize_doi(doi, options = {})
@@ -41,9 +41,9 @@ module Briard
41
41
  end
42
42
 
43
43
  def doi_from_url(url)
44
- if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(url)
44
+ if %r{\A(?:(http|https)://(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match?(url)
45
45
  uri = Addressable::URI.parse(url)
46
- uri.path.gsub(/^\//, '').downcase
46
+ uri.path.gsub(%r{^/}, '').downcase
47
47
  end
48
48
  end
49
49
 
@@ -59,7 +59,7 @@ module Briard
59
59
  url = "https://doi.org/ra/#{prefix}"
60
60
  result = Maremma.get(url)
61
61
 
62
- result.body.dig("data", 0, "RA")
62
+ result.body.dig('data', 0, 'RA')
63
63
  end
64
64
  end
65
65
  end