briard 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.github/workflows/rubocop.yml +50 -0
- data/.rubocop.yml +144 -620
- data/.rubocop_todo.yml +76 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +43 -6
- data/Rakefile +1 -1
- data/{bolognese.gemspec → briard.gemspec} +46 -38
- data/lib/briard/array.rb +2 -2
- data/lib/briard/author_utils.rb +79 -71
- data/lib/briard/cli.rb +12 -13
- data/lib/briard/crossref_utils.rb +73 -61
- data/lib/briard/datacite_utils.rb +132 -106
- data/lib/briard/doi_utils.rb +10 -10
- data/lib/briard/metadata.rb +96 -106
- data/lib/briard/metadata_utils.rb +87 -78
- data/lib/briard/readers/bibtex_reader.rb +65 -65
- data/lib/briard/readers/cff_reader.rb +88 -70
- data/lib/briard/readers/citeproc_reader.rb +90 -84
- data/lib/briard/readers/codemeta_reader.rb +68 -50
- data/lib/briard/readers/crosscite_reader.rb +2 -2
- data/lib/briard/readers/crossref_reader.rb +249 -210
- data/lib/briard/readers/datacite_json_reader.rb +3 -3
- data/lib/briard/readers/datacite_reader.rb +225 -189
- data/lib/briard/readers/npm_reader.rb +49 -42
- data/lib/briard/readers/ris_reader.rb +82 -80
- data/lib/briard/readers/schema_org_reader.rb +182 -159
- data/lib/briard/string.rb +1 -1
- data/lib/briard/utils.rb +4 -4
- data/lib/briard/version.rb +3 -1
- data/lib/briard/whitelist_scrubber.rb +11 -4
- data/lib/briard/writers/bibtex_writer.rb +14 -8
- data/lib/briard/writers/cff_writer.rb +33 -26
- data/lib/briard/writers/codemeta_writer.rb +19 -15
- data/lib/briard/writers/csv_writer.rb +6 -4
- data/lib/briard/writers/datacite_json_writer.rb +8 -2
- data/lib/briard/writers/jats_writer.rb +33 -28
- data/lib/briard/writers/rdf_xml_writer.rb +1 -1
- data/lib/briard/writers/ris_writer.rb +30 -18
- data/lib/briard/writers/turtle_writer.rb +1 -1
- data/lib/briard.rb +6 -6
- data/rubocop.sarif +0 -0
- data/spec/array_spec.rb +5 -5
- data/spec/author_utils_spec.rb +151 -132
- data/spec/datacite_utils_spec.rb +135 -83
- data/spec/doi_utils_spec.rb +168 -164
- data/spec/find_from_format_spec.rb +69 -69
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/onlies_keep_specific_tags.yml +65 -0
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/removes_a_tags.yml +65 -0
- data/spec/metadata_spec.rb +91 -90
- data/spec/readers/bibtex_reader_spec.rb +43 -38
- data/spec/readers/cff_reader_spec.rb +165 -153
- data/spec/readers/citeproc_reader_spec.rb +45 -40
- data/spec/readers/codemeta_reader_spec.rb +128 -115
- data/spec/readers/crosscite_reader_spec.rb +34 -24
- data/spec/readers/crossref_reader_spec.rb +1098 -939
- data/spec/readers/datacite_json_reader_spec.rb +53 -40
- data/spec/readers/datacite_reader_spec.rb +1541 -1337
- data/spec/readers/npm_reader_spec.rb +48 -43
- data/spec/readers/ris_reader_spec.rb +53 -47
- data/spec/readers/schema_org_reader_spec.rb +329 -267
- data/spec/spec_helper.rb +6 -5
- data/spec/utils_spec.rb +371 -347
- data/spec/writers/bibtex_writer_spec.rb +143 -143
- data/spec/writers/cff_writer_spec.rb +96 -90
- data/spec/writers/citation_writer_spec.rb +34 -33
- data/spec/writers/citeproc_writer_spec.rb +226 -224
- data/spec/writers/codemeta_writer_spec.rb +18 -16
- data/spec/writers/crosscite_writer_spec.rb +91 -73
- data/spec/writers/crossref_writer_spec.rb +99 -91
- data/spec/writers/csv_writer_spec.rb +70 -70
- data/spec/writers/datacite_json_writer_spec.rb +78 -68
- data/spec/writers/datacite_writer_spec.rb +417 -322
- data/spec/writers/jats_writer_spec.rb +177 -161
- data/spec/writers/rdf_xml_writer_spec.rb +68 -63
- data/spec/writers/ris_writer_spec.rb +162 -162
- data/spec/writers/turtle_writer_spec.rb +47 -47
- metadata +250 -160
- 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(:
|
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',
|
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
|
-
|
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(
|
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
|
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' =>
|
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,
|
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(
|
74
|
-
insert_person(xml, con,
|
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[
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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[
|
90
|
-
attributes = {
|
91
|
-
|
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[
|
112
|
+
t['title'] = title
|
103
113
|
end
|
104
114
|
|
105
|
-
attributes = { 'titleType' => t[
|
106
|
-
xml.title(t[
|
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[
|
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
|
-
|
130
|
+
unless types.is_a?(Hash) && (types['schemaOrg'].present? || types['resourceTypeGeneral'])
|
131
|
+
return xml
|
132
|
+
end
|
121
133
|
|
122
|
-
xml.resourceType(types[
|
123
|
-
|
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).
|
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[
|
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[
|
143
|
-
|
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[
|
155
|
-
|
156
|
-
|
157
|
-
|
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[
|
194
|
+
s['subject'] = subject
|
173
195
|
end
|
174
196
|
|
175
|
-
attributes = {
|
197
|
+
attributes = { 'subjectScheme' => s['subjectScheme'], 'schemeURI' => s['schemeUri'],
|
198
|
+
'valueURI' => s['valueUri'], 'xml:lang' => s['lang'] }.compact
|
176
199
|
|
177
|
-
xml.subject(s[
|
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[
|
202
|
-
'relationType' => related_identifier[
|
203
|
-
'resourceTypeGeneral' => related_identifier[
|
223
|
+
'relatedIdentifierType' => related_identifier['relatedIdentifierType'],
|
224
|
+
'relationType' => related_identifier['relationType'],
|
225
|
+
'resourceTypeGeneral' => related_identifier['resourceTypeGeneral']
|
226
|
+
}.compact
|
204
227
|
|
205
|
-
|
206
|
-
'
|
207
|
-
|
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[
|
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[
|
221
|
-
'relationType' => related_item[
|
245
|
+
'relatedItemType' => related_item['relatedItemType'],
|
246
|
+
'relationType' => related_item['relationType']
|
222
247
|
}.compact
|
223
248
|
|
224
|
-
xml.relatedItem(related_item[
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
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,
|
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[
|
272
|
+
t['title'] = title
|
250
273
|
end
|
251
274
|
|
252
|
-
attributes = { 'titleType' => t[
|
253
|
-
xml.title(t[
|
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'],
|
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[
|
268
|
-
xml.contributor(
|
269
|
-
insert_person(xml, con,
|
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[
|
305
|
-
r[
|
327
|
+
r['rights'] = rights
|
328
|
+
r['rightsUri'] = normalize_id(rights)
|
306
329
|
end
|
307
330
|
|
308
331
|
attributes = {
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
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[
|
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[
|
345
|
+
return xml unless descriptions.present? || (container && container['title'].present?)
|
323
346
|
|
324
347
|
xml.descriptions do
|
325
|
-
if container && container[
|
326
|
-
issue = container[
|
327
|
-
volume_issue = container[
|
328
|
-
|
329
|
-
|
330
|
-
|
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[
|
339
|
-
d[
|
363
|
+
d['description'] = description
|
364
|
+
d['descriptionType'] = 'Abstract'
|
340
365
|
end
|
341
366
|
|
342
|
-
attributes = { 'xml:lang' => d[
|
367
|
+
attributes = { 'xml:lang' => d['lang'],
|
368
|
+
'descriptionType' => d['descriptionType'] || 'Abstract' }.compact
|
343
369
|
|
344
|
-
xml.description(d[
|
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
|
-
|
381
|
+
if geo_location['geoLocationPlace']
|
382
|
+
xml.geoLocationPlace(geo_location['geoLocationPlace'])
|
383
|
+
end
|
356
384
|
|
357
|
-
if geo_location[
|
385
|
+
if geo_location['geoLocationPoint']
|
358
386
|
xml.geoLocationPoint do
|
359
|
-
xml.pointLatitude(geo_location.dig(
|
360
|
-
xml.pointLongitude(geo_location.dig(
|
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[
|
392
|
+
if geo_location['geoLocationBox']
|
365
393
|
xml.geoLocationBox do
|
366
|
-
xml.westBoundLongitude(geo_location.dig(
|
367
|
-
xml.eastBoundLongitude(geo_location.dig(
|
368
|
-
xml.southBoundLatitude(geo_location.dig(
|
369
|
-
xml.northBoundLatitude(geo_location.dig(
|
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
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
xml.polygonPoint
|
377
|
-
|
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
|
-
{
|
391
|
-
|
392
|
-
:
|
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
|
data/lib/briard/doi_utils.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
module Briard
|
4
4
|
module DoiUtils
|
5
5
|
def validate_doi(doi)
|
6
|
-
doi = Array(
|
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(
|
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(
|
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
|
27
|
-
sandbox.present? || options[:sandbox] ?
|
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
|
32
|
-
sandbox.present? || options[:sandbox] ? "https://api.stage.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
|
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(
|
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(
|
62
|
+
result.body.dig('data', 0, 'RA')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|