commonmeta-ruby 3.2.7 → 3.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -7
- data/lib/commonmeta/crossref_utils.rb +79 -77
- data/lib/commonmeta/version.rb +1 -1
- data/spec/writers/crossref_xml_writer_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e05b0fedfc5074f16bf6b04dd73150dcae6f75d3392dd3abe82bd52eafea1531
|
4
|
+
data.tar.gz: 12700c970a507ae36013334f0e942413f0092d6bf4735aa27b6709a12bc7d84e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c86b93355c0337df66c15d519f51f5336f2f883924f1c6b2edad8b6460d509d2e3443653d8545b201004e6407afffe79a505044f8cae88bbeede9f25e16171
|
7
|
+
data.tar.gz: 903e7a8af1ec1025f8e7125ed96eea07f0994ed71f1473c5111947e5d7c8c1e42c5dcbe2b0562e261f60515c374c5f23e1d593cf448b9a87962cd4f3c831e2a3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
commonmeta-ruby (3.2.
|
4
|
+
commonmeta-ruby (3.2.9)
|
5
5
|
activesupport (>= 4.2.5, < 8.0)
|
6
6
|
addressable (~> 2.8.1, < 2.8.2)
|
7
7
|
base32-url (>= 0.5.0, < 1)
|
@@ -103,7 +103,7 @@ GEM
|
|
103
103
|
json-ld-preloaded (3.2.2)
|
104
104
|
json-ld (~> 3.2)
|
105
105
|
rdf (~> 3.2)
|
106
|
-
json_schemer (1.0.
|
106
|
+
json_schemer (1.0.3)
|
107
107
|
hana (~> 1.3)
|
108
108
|
regexp_parser (~> 2.0)
|
109
109
|
simpleidn (~> 0.2)
|
@@ -138,8 +138,8 @@ GEM
|
|
138
138
|
props (1.2.0)
|
139
139
|
iniparser (>= 0.1.0)
|
140
140
|
public_suffix (4.0.7)
|
141
|
-
racc (1.7.
|
142
|
-
rack (3.0.
|
141
|
+
racc (1.7.1)
|
142
|
+
rack (3.0.8)
|
143
143
|
rack-test (2.1.0)
|
144
144
|
rack (>= 1.3)
|
145
145
|
rainbow (3.1.1)
|
@@ -169,7 +169,7 @@ GEM
|
|
169
169
|
rdf-xsd (3.2.1)
|
170
170
|
rdf (~> 3.2)
|
171
171
|
rexml (~> 3.2)
|
172
|
-
regexp_parser (2.8.
|
172
|
+
regexp_parser (2.8.1)
|
173
173
|
rexml (3.2.5)
|
174
174
|
rspec (3.12.0)
|
175
175
|
rspec-core (~> 3.12.0)
|
@@ -187,10 +187,10 @@ GEM
|
|
187
187
|
rspec-xsd (0.1.0)
|
188
188
|
nokogiri (~> 1.6)
|
189
189
|
rspec (~> 3)
|
190
|
-
rubocop (1.52.
|
190
|
+
rubocop (1.52.1)
|
191
191
|
json (~> 2.3)
|
192
192
|
parallel (~> 1.10)
|
193
|
-
parser (>= 3.2.
|
193
|
+
parser (>= 3.2.2.3)
|
194
194
|
rainbow (>= 2.2.2, < 4.0)
|
195
195
|
regexp_parser (>= 1.8, < 3.0)
|
196
196
|
rexml (>= 3.2.5, < 4.0)
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Commonmeta
|
4
4
|
module CrossrefUtils
|
5
5
|
def write_crossref_xml
|
6
|
-
@crossref_xml ||= Nokogiri::XML::Builder.new(encoding:
|
6
|
+
@crossref_xml ||= Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
7
7
|
xml.doi_batch(crossref_root_attributes) do
|
8
8
|
xml.head do
|
9
9
|
# we use a uuid as batch_id
|
10
10
|
xml.doi_batch_id(SecureRandom.uuid)
|
11
|
-
xml.timestamp(Time.now.utc.strftime(
|
11
|
+
xml.timestamp(Time.now.utc.strftime("%Y%m%d%H%M%S"))
|
12
12
|
xml.depositor do
|
13
13
|
xml.depositor_name(depositor)
|
14
14
|
xml.email_address(email)
|
@@ -23,12 +23,12 @@ module Commonmeta
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def crossref_errors(xml: nil)
|
26
|
-
filepath = File.expand_path(
|
27
|
-
File.open(filepath,
|
26
|
+
filepath = File.expand_path("../../resources/crossref/crossref5.3.1.xsd", __dir__)
|
27
|
+
File.open(filepath, "r") do |f|
|
28
28
|
schema = Nokogiri::XML::Schema(f)
|
29
29
|
end
|
30
30
|
|
31
|
-
schema.validate(Nokogiri::XML(xml, nil,
|
31
|
+
schema.validate(Nokogiri::XML(xml, nil, "UTF-8")).map(&:to_s).unwrap
|
32
32
|
rescue Nokogiri::XML::SyntaxError => e
|
33
33
|
e.message
|
34
34
|
end
|
@@ -37,9 +37,9 @@ module Commonmeta
|
|
37
37
|
return xml if doi_from_url(id).blank?
|
38
38
|
|
39
39
|
case type
|
40
|
-
when
|
40
|
+
when "JournalArticle"
|
41
41
|
insert_journal(xml)
|
42
|
-
when
|
42
|
+
when "Article"
|
43
43
|
insert_posted_content(xml)
|
44
44
|
end
|
45
45
|
end
|
@@ -47,20 +47,21 @@ module Commonmeta
|
|
47
47
|
def insert_journal(xml)
|
48
48
|
xml.journal do
|
49
49
|
if language.present?
|
50
|
-
xml.journal_metadata(
|
51
|
-
xml.full_title(container[
|
50
|
+
xml.journal_metadata("language" => language[0..1]) do
|
51
|
+
xml.full_title(container["title"])
|
52
52
|
end
|
53
53
|
else
|
54
54
|
xml.journal_metadata do
|
55
|
-
xml.full_title(container[
|
55
|
+
xml.full_title(container["title"])
|
56
56
|
end
|
57
57
|
end
|
58
|
-
xml.journal_article(
|
58
|
+
xml.journal_article("publication_type" => "full_text") do
|
59
59
|
insert_crossref_titles(xml)
|
60
60
|
insert_crossref_creators(xml)
|
61
61
|
insert_crossref_publication_date(xml)
|
62
62
|
insert_crossref_abstract(xml)
|
63
63
|
insert_crossref_issn(xml)
|
64
|
+
insert_item_number(xml)
|
64
65
|
insert_crossref_access_indicators(xml)
|
65
66
|
insert_doi_data(xml)
|
66
67
|
insert_citation_list(xml)
|
@@ -69,7 +70,7 @@ module Commonmeta
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def insert_posted_content(xml)
|
72
|
-
posted_content = {
|
73
|
+
posted_content = { "type" => "other", "language" => language ? language[0..1] : nil }.compact
|
73
74
|
|
74
75
|
xml.posted_content(posted_content) do
|
75
76
|
insert_group_title(xml)
|
@@ -77,7 +78,7 @@ module Commonmeta
|
|
77
78
|
insert_crossref_titles(xml)
|
78
79
|
insert_posted_date(xml)
|
79
80
|
insert_institution(xml)
|
80
|
-
|
81
|
+
insert_item_number(xml)
|
81
82
|
insert_crossref_abstract(xml)
|
82
83
|
insert_crossref_access_indicators(xml)
|
83
84
|
insert_doi_data(xml)
|
@@ -88,14 +89,14 @@ module Commonmeta
|
|
88
89
|
def insert_group_title(xml)
|
89
90
|
return xml if subjects.blank?
|
90
91
|
|
91
|
-
xml.group_title(subjects.first[
|
92
|
+
xml.group_title(subjects.first["subject"].titleize)
|
92
93
|
end
|
93
94
|
|
94
95
|
def insert_crossref_creators(xml)
|
95
96
|
xml.contributors do
|
96
97
|
Array.wrap(creators).each_with_index do |person, index|
|
97
|
-
xml.person_name(
|
98
|
-
|
98
|
+
xml.person_name("contributor_role" => "author",
|
99
|
+
"sequence" => index.zero? ? "first" : "additional") do
|
99
100
|
insert_crossref_person(xml, person)
|
100
101
|
end
|
101
102
|
end
|
@@ -103,15 +104,15 @@ module Commonmeta
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def insert_crossref_person(xml, person)
|
106
|
-
xml.given_name(person[
|
107
|
-
xml.surname(person[
|
108
|
-
if person.dig(
|
109
|
-
xml.ORCID(person.dig(
|
107
|
+
xml.given_name(person["givenName"]) if person["givenName"].present?
|
108
|
+
xml.surname(person["familyName"]) if person["familyName"].present?
|
109
|
+
if person.dig("id") && URI.parse(person.dig("id")).host == "orcid.org"
|
110
|
+
xml.ORCID(person.dig("id"))
|
110
111
|
end
|
111
|
-
Array.wrap(person[
|
112
|
-
attributes = {
|
113
|
-
|
114
|
-
xml.affiliation(affiliation[
|
112
|
+
Array.wrap(person["affiliation"]).each do |affiliation|
|
113
|
+
attributes = { "affiliationIdentifier" => affiliation["affiliationIdentifier"],
|
114
|
+
"affiliationIdentifierScheme" => affiliation["affiliationIdentifierScheme"], "schemeURI" => affiliation["schemeUri"] }.compact
|
115
|
+
xml.affiliation(affiliation["name"], attributes)
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
@@ -119,7 +120,7 @@ module Commonmeta
|
|
119
120
|
xml.titles do
|
120
121
|
Array.wrap(titles).each do |title|
|
121
122
|
if title.is_a?(Hash)
|
122
|
-
xml.title(title[
|
123
|
+
xml.title(title["title"])
|
123
124
|
else
|
124
125
|
xml.title(title)
|
125
126
|
end
|
@@ -130,15 +131,15 @@ module Commonmeta
|
|
130
131
|
def insert_citation_list(xml)
|
131
132
|
xml.citation_list do
|
132
133
|
Array.wrap(references).each do |ref|
|
133
|
-
xml.citation(
|
134
|
-
xml.journal_article(ref[
|
135
|
-
xml.author(ref[
|
136
|
-
xml.volume(ref[
|
137
|
-
xml.first_page(ref[
|
138
|
-
xml.cYear(ref[
|
139
|
-
xml.article_title(ref[
|
140
|
-
xml.doi(ref[
|
141
|
-
xml.unstructured_citation(ref[
|
134
|
+
xml.citation("key" => ref["key"]) do
|
135
|
+
xml.journal_article(ref["journal_title"]) if ref["journal_title"].present?
|
136
|
+
xml.author(ref["author"]) if ref["author"].present?
|
137
|
+
xml.volume(ref["volume"]) if ref["volume"].present?
|
138
|
+
xml.first_page(ref["first_page"]) if ref["first_page"].present?
|
139
|
+
xml.cYear(ref["cYear"]) if ref["cYear"].present?
|
140
|
+
xml.article_title(ref["article_title"]) if ref["article_title"].present?
|
141
|
+
xml.doi(doi_from_url(ref["doi"])) if ref["doi"].present?
|
142
|
+
xml.unstructured_citation(ref["url"]) if ref["url"].present?
|
142
143
|
end
|
143
144
|
end
|
144
145
|
end
|
@@ -162,12 +163,12 @@ module Commonmeta
|
|
162
163
|
def insert_crossref_access_indicators(xml)
|
163
164
|
return xml if license.blank?
|
164
165
|
|
165
|
-
rights_uri = license[
|
166
|
+
rights_uri = license["url"]
|
166
167
|
|
167
|
-
xml.program(
|
168
|
-
|
169
|
-
xml.license_ref(rights_uri,
|
170
|
-
xml.license_ref(rights_uri,
|
168
|
+
xml.program("xmlns" => "http://www.crossref.org/AccessIndicators.xsd",
|
169
|
+
"name" => "AccessIndicators") do
|
170
|
+
xml.license_ref(rights_uri, "applies_to" => "vor")
|
171
|
+
xml.license_ref(rights_uri, "applies_to" => "tdm")
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
@@ -203,7 +204,7 @@ module Commonmeta
|
|
203
204
|
xml.subjects do
|
204
205
|
subjects.each do |subject|
|
205
206
|
if subject.is_a?(Hash)
|
206
|
-
xml.subject(subject[
|
207
|
+
xml.subject(subject["subject"])
|
207
208
|
else
|
208
209
|
xml.subject(subject)
|
209
210
|
end
|
@@ -224,11 +225,11 @@ module Commonmeta
|
|
224
225
|
end
|
225
226
|
|
226
227
|
def insert_crossref_publication_date(xml)
|
227
|
-
return xml if date[
|
228
|
+
return xml if date["registered"].blank?
|
228
229
|
|
229
|
-
date_ = get_datetime_from_iso8601(date[
|
230
|
+
date_ = get_datetime_from_iso8601(date["registered"])
|
230
231
|
|
231
|
-
xml.publication_date(
|
232
|
+
xml.publication_date("media_type" => "online") do
|
232
233
|
xml.month(date_.month) if date_.month.present?
|
233
234
|
xml.day(date_.day) if date_.day.present?
|
234
235
|
xml.year(date_.year) if date_.year.present?
|
@@ -236,9 +237,9 @@ module Commonmeta
|
|
236
237
|
end
|
237
238
|
|
238
239
|
def insert_posted_date(xml)
|
239
|
-
return xml if date[
|
240
|
+
return xml if date["published"].blank?
|
240
241
|
|
241
|
-
date_ = get_datetime_from_iso8601(date[
|
242
|
+
date_ = get_datetime_from_iso8601(date["published"])
|
242
243
|
|
243
244
|
xml.posted_date do
|
244
245
|
xml.month(date_.month) if date_.month.present?
|
@@ -251,21 +252,22 @@ module Commonmeta
|
|
251
252
|
return xml if publisher.blank?
|
252
253
|
|
253
254
|
xml.institution do
|
254
|
-
xml.institution_name(publisher[
|
255
|
+
xml.institution_name(publisher["name"])
|
255
256
|
end
|
256
257
|
end
|
257
258
|
|
258
|
-
def
|
259
|
+
def insert_item_number(xml)
|
259
260
|
return xml if alternate_identifiers.blank?
|
260
261
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}.compact
|
262
|
+
alternate_identifiers.each do |alternate_identifier|
|
263
|
+
attributes = {
|
264
|
+
"item_number_type" => alternate_identifier["alternateIdentifierType"] ? alternate_identifier["alternateIdentifierType"].downcase : nil,
|
265
|
+
}.compact
|
266
266
|
|
267
|
-
|
268
|
-
|
267
|
+
# remove dashes from UUIDs, as item_number can only be 32 characters long
|
268
|
+
alternate_identifier["alternateIdentifier"].gsub!("-", "") if alternate_identifier["alternateIdentifierType"] == "UUID"
|
269
|
+
|
270
|
+
xml.item_number(alternate_identifier["alternateIdentifier"], attributes)
|
269
271
|
end
|
270
272
|
end
|
271
273
|
|
@@ -275,9 +277,9 @@ module Commonmeta
|
|
275
277
|
xml.doi_data do
|
276
278
|
xml.doi(doi_from_url(id).downcase)
|
277
279
|
xml.resource(url)
|
278
|
-
xml.collection(
|
280
|
+
xml.collection("property" => "text-mining") do
|
279
281
|
xml.item do
|
280
|
-
xml.resource(url,
|
282
|
+
xml.resource(url, "mime_type" => "text/html")
|
281
283
|
end
|
282
284
|
end
|
283
285
|
end
|
@@ -292,26 +294,26 @@ module Commonmeta
|
|
292
294
|
r = rights
|
293
295
|
else
|
294
296
|
r = {}
|
295
|
-
r[
|
296
|
-
r[
|
297
|
+
r["rights"] = rights
|
298
|
+
r["rightsUri"] = normalize_id(rights)
|
297
299
|
end
|
298
300
|
|
299
301
|
attributes = {
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
302
|
+
"rightsURI" => r["rightsUri"],
|
303
|
+
"rightsIdentifier" => r["rightsIdentifier"],
|
304
|
+
"rightsIdentifierScheme" => r["rightsIdentifierScheme"],
|
305
|
+
"schemeURI" => r["schemeUri"],
|
306
|
+
"xml:lang" => r["lang"],
|
305
307
|
}.compact
|
306
308
|
|
307
|
-
xml.rights(r[
|
309
|
+
xml.rights(r["rights"], attributes)
|
308
310
|
end
|
309
311
|
end
|
310
312
|
|
311
313
|
def insert_crossref_issn(xml)
|
312
|
-
issn = if container.to_h.fetch(
|
313
|
-
|
314
|
-
|
314
|
+
issn = if container.to_h.fetch("identifierType", nil) == "ISSN"
|
315
|
+
container.to_h.fetch("identifier", nil)
|
316
|
+
end
|
315
317
|
|
316
318
|
return xml if issn.blank?
|
317
319
|
|
@@ -325,22 +327,22 @@ module Commonmeta
|
|
325
327
|
d = descriptions.first
|
326
328
|
else
|
327
329
|
d = {}
|
328
|
-
d[
|
330
|
+
d["description"] = descriptions.first
|
329
331
|
end
|
330
332
|
|
331
|
-
xml.abstract(
|
332
|
-
xml.p(d[
|
333
|
+
xml.abstract("xmlns" => "http://www.ncbi.nlm.nih.gov/JATS1") do
|
334
|
+
xml.p(d["description"])
|
333
335
|
end
|
334
336
|
end
|
335
337
|
|
336
338
|
def crossref_root_attributes
|
337
|
-
{ 'xmlns:xsi':
|
338
|
-
'xsi:schemaLocation':
|
339
|
-
xmlns:
|
340
|
-
'xmlns:jats':
|
341
|
-
'xmlns:fr':
|
342
|
-
'xmlns:mml':
|
343
|
-
version:
|
339
|
+
{ 'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance",
|
340
|
+
'xsi:schemaLocation': "http://www.crossref.org/schema/5.3.1 https://www.crossref.org/schemas/crossref5.3.1.xsd",
|
341
|
+
xmlns: "http://www.crossref.org/schema/5.3.1",
|
342
|
+
'xmlns:jats': "http://www.ncbi.nlm.nih.gov/JATS1",
|
343
|
+
'xmlns:fr': "http://www.crossref.org/fundref.xsd",
|
344
|
+
'xmlns:mml': "http://www.w3.org/1998/Math/MathML",
|
345
|
+
version: "5.3.1" }
|
344
346
|
end
|
345
347
|
end
|
346
348
|
end
|
data/lib/commonmeta/version.rb
CHANGED
@@ -217,8 +217,8 @@ describe Commonmeta::Metadata, vcr: true do
|
|
217
217
|
expect(crossref_xml.dig("titles",
|
218
218
|
"title")).to eq("The Research Software Alliance (ReSA)")
|
219
219
|
expect(crossref_xml.dig("citation_list", "citation").length).to eq(11)
|
220
|
-
expect(crossref_xml.dig("citation_list", "citation").last).to eq("doi"=>"
|
221
|
-
expect(crossref_xml.dig('
|
220
|
+
expect(crossref_xml.dig("citation_list", "citation").last).to eq("doi"=>"10.5281/zenodo.3699950", "key"=>"ref11")
|
221
|
+
expect(crossref_xml.dig('item_number')).to eq("__content__"=>"954f81380ecd409087c5cef1297f1470", "item_number_type"=>"uuid")
|
222
222
|
end
|
223
223
|
|
224
224
|
it "json_feed_item from rogue scholar with doi" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmeta-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Fenner
|
@@ -1419,7 +1419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1419
1419
|
- !ruby/object:Gem::Version
|
1420
1420
|
version: '0'
|
1421
1421
|
requirements: []
|
1422
|
-
rubygems_version: 3.4.
|
1422
|
+
rubygems_version: 3.4.14
|
1423
1423
|
signing_key:
|
1424
1424
|
specification_version: 4
|
1425
1425
|
summary: Ruby client library for conversion of scholarly metadata
|