commonmeta-ruby 3.2.12 → 3.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/commonmeta +1 -1
- data/lib/commonmeta/cli.rb +3 -3
- data/lib/commonmeta/crossref_utils.rb +3 -3
- data/lib/commonmeta/readers/json_feed_reader.rb +7 -7
- data/lib/commonmeta/readers/schema_org_reader.rb +1 -1
- data/lib/commonmeta/utils.rb +8 -5
- data/lib/commonmeta/version.rb +1 -1
- data/lib/commonmeta/writers/bibtex_writer.rb +1 -1
- data/lib/commonmeta/writers/ris_writer.rb +1 -1
- data/lib/commonmeta/writers/schema_org_writer.rb +1 -1
- data/spec/cli_spec.rb +9 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_not_indexed.yml +2155 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_unregistered.yml +2010 -0
- data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_feed/not_indexed_posts.yml +2155 -0
- data/spec/readers/cff_reader_spec.rb +33 -33
- data/spec/readers/codemeta_reader_spec.rb +8 -8
- data/spec/readers/json_feed_reader_spec.rb +40 -12
- data/spec/readers/schema_org_reader_spec.rb +38 -38
- data/spec/utils_spec.rb +3 -3
- data/spec/writers/bibtex_writer_spec.rb +3 -3
- data/spec/writers/cff_writer_spec.rb +2 -2
- data/spec/writers/crossref_xml_writer_spec.rb +21 -9
- data/spec/writers/ris_writer_spec.rb +8 -8
- data/spec/writers/schema_org_writer_spec.rb +6 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b549fc46c70c5962ee3c971968771a6e5f13124eb89b03aab36228afc94c01fe
|
4
|
+
data.tar.gz: 1545d0de4e821265cc19bb744456d025f6bc14ea52c19cbae2585a1d501501a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d7a785d1fdbf3bd226a64f489ef12e37cb474fe0334c894e98c0a86b90fba23d02d937eed3bc4f4e710791209556ab2ece950e50491d48874e128e95f62c44e
|
7
|
+
data.tar.gz: cad955e4ba4066a42ff821f03437cfe09fb926c283785050d34682cc95e676d89d608f03ca63c18574d012e5fcad168c5f289cd7d465f525846c877e91368635
|
data/Gemfile.lock
CHANGED
data/bin/commonmeta
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require File.expand_path("../../lib/commonmeta", __FILE__)
|
4
4
|
|
5
|
-
if (ARGV & %w(--version -v help --help encode decode encode_id decode_id
|
5
|
+
if (ARGV & %w(--version -v help --help encode decode encode_id decode_id json_feed_not_indexed json_feed_unregistered json_feed_by_blog)).empty?
|
6
6
|
Commonmeta::CLI.start(ARGV.dup.unshift("convert"))
|
7
7
|
else
|
8
8
|
Commonmeta::CLI.start
|
data/lib/commonmeta/cli.rb
CHANGED
@@ -86,10 +86,10 @@ module Commonmeta
|
|
86
86
|
puts get_json_feed_unregistered
|
87
87
|
end
|
88
88
|
|
89
|
-
desc "", "
|
89
|
+
desc "", "json_feed_not_indexed"
|
90
90
|
|
91
|
-
def
|
92
|
-
puts
|
91
|
+
def json_feed_not_indexed(date_indexed)
|
92
|
+
puts get_json_feed_not_indexed(date_indexed)
|
93
93
|
end
|
94
94
|
|
95
95
|
desc "", "json_feed_by_blog"
|
@@ -89,7 +89,7 @@ module Commonmeta
|
|
89
89
|
def insert_group_title(xml)
|
90
90
|
return xml if subjects.blank?
|
91
91
|
|
92
|
-
xml.group_title(subjects.first["subject"]
|
92
|
+
xml.group_title(subjects.first["subject"])
|
93
93
|
end
|
94
94
|
|
95
95
|
def insert_crossref_creators(xml)
|
@@ -264,8 +264,8 @@ module Commonmeta
|
|
264
264
|
"item_number_type" => alternate_identifier["alternateIdentifierType"] ? alternate_identifier["alternateIdentifierType"].downcase : nil,
|
265
265
|
}.compact
|
266
266
|
|
267
|
-
#
|
268
|
-
alternate_identifier["alternateIdentifier"] =
|
267
|
+
# strip hyphen from UUIDs, as item_number can only be 32 characters long (UUIDv4 is 36 characters long)
|
268
|
+
alternate_identifier["alternateIdentifier"] = alternate_identifier["alternateIdentifier"].gsub('-','') if alternate_identifier["alternateIdentifierType"] == "UUID"
|
269
269
|
|
270
270
|
xml.item_number(alternate_identifier["alternateIdentifier"], attributes)
|
271
271
|
end
|
@@ -54,7 +54,7 @@ module Commonmeta
|
|
54
54
|
end
|
55
55
|
language = meta.fetch("language", nil) || meta.dig("blog", "language")
|
56
56
|
state = id.present? || read_options.present? ? "findable" : "not_found"
|
57
|
-
subjects = Array.wrap(meta.
|
57
|
+
subjects = Array.wrap(meta.dig("blog", "category")).reduce([]) do |sum, subject|
|
58
58
|
sum += name_to_fos(subject)
|
59
59
|
|
60
60
|
sum
|
@@ -96,18 +96,18 @@ module Commonmeta
|
|
96
96
|
return { "string" => nil, "state" => "not_found" } unless response.status.success?
|
97
97
|
|
98
98
|
posts = JSON.parse(response.body.to_s)
|
99
|
-
posts.map { |post| post["uuid"] }.
|
99
|
+
posts.map { |post| post["uuid"] }.first
|
100
100
|
end
|
101
101
|
|
102
|
-
def
|
103
|
-
# get JSON Feed items
|
102
|
+
def get_json_feed_not_indexed(date_indexed)
|
103
|
+
# get JSON Feed items not indexed in Crossref since a particular date
|
104
104
|
|
105
|
-
url =
|
105
|
+
url = json_feed_not_indexed_url(date_indexed)
|
106
106
|
response = HTTP.get(url)
|
107
107
|
return { "string" => nil, "state" => "not_found" } unless response.status.success?
|
108
108
|
|
109
109
|
posts = JSON.parse(response.body.to_s)
|
110
|
-
posts.map { |post| post["uuid"] }.
|
110
|
+
posts.map { |post| post["uuid"] }.first
|
111
111
|
end
|
112
112
|
|
113
113
|
def get_json_feed_by_blog(blog_id)
|
@@ -118,7 +118,7 @@ module Commonmeta
|
|
118
118
|
return { "string" => nil, "state" => "not_found" } unless response.status.success?
|
119
119
|
|
120
120
|
blog = JSON.parse(response.body.to_s)
|
121
|
-
blog["items"].map { |item| item["uuid"] }.
|
121
|
+
blog["items"].map { |item| item["uuid"] }.first
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -208,7 +208,7 @@ module Commonmeta
|
|
208
208
|
|
209
209
|
# handle keywords as array and as comma-separated string
|
210
210
|
subjects = meta.fetch('keywords', nil)
|
211
|
-
subjects = subjects.to_s.
|
211
|
+
subjects = subjects.to_s.split(', ') if subjects.is_a?(String)
|
212
212
|
subjects = Array.wrap(subjects).reduce([]) do |sum, subject|
|
213
213
|
sum += name_to_fos(subject)
|
214
214
|
sum
|
data/lib/commonmeta/utils.rb
CHANGED
@@ -1253,6 +1253,9 @@ module Commonmeta
|
|
1253
1253
|
end
|
1254
1254
|
|
1255
1255
|
def name_to_fos(name)
|
1256
|
+
# make sure name is capitalized
|
1257
|
+
name = name.capitalize
|
1258
|
+
|
1256
1259
|
# first find subject in Fields of Science (OECD)
|
1257
1260
|
fos = JSON.load(File.read(File.expand_path("../../resources/oecd/fos-mappings.json",
|
1258
1261
|
__dir__))).fetch("fosFields")
|
@@ -1261,7 +1264,7 @@ module Commonmeta
|
|
1261
1264
|
|
1262
1265
|
if subject
|
1263
1266
|
return [{
|
1264
|
-
"subject" => sanitize(name)
|
1267
|
+
"subject" => sanitize(name),
|
1265
1268
|
},
|
1266
1269
|
{
|
1267
1270
|
"subject" => "FOS: " + subject["fosLabel"],
|
@@ -1282,7 +1285,7 @@ module Commonmeta
|
|
1282
1285
|
|
1283
1286
|
if subject
|
1284
1287
|
[{
|
1285
|
-
"subject" => sanitize(name)
|
1288
|
+
"subject" => sanitize(name),
|
1286
1289
|
},
|
1287
1290
|
{
|
1288
1291
|
"subject" => "FOS: " + subject["fosLabel"],
|
@@ -1290,7 +1293,7 @@ module Commonmeta
|
|
1290
1293
|
"schemeUri" => "http://www.oecd.org/science/inno/38235147.pdf",
|
1291
1294
|
}]
|
1292
1295
|
else
|
1293
|
-
[{ "subject" => sanitize(name)
|
1296
|
+
[{ "subject" => sanitize(name) }]
|
1294
1297
|
end
|
1295
1298
|
end
|
1296
1299
|
|
@@ -1401,8 +1404,8 @@ module Commonmeta
|
|
1401
1404
|
Base32::URL.decode(id)
|
1402
1405
|
end
|
1403
1406
|
|
1404
|
-
def
|
1405
|
-
"https://rogue-scholar.org/api/posts/
|
1407
|
+
def json_feed_not_indexed_url(date_indexed)
|
1408
|
+
"https://rogue-scholar.org/api/posts/not_indexed/#{date_indexed}"
|
1406
1409
|
end
|
1407
1410
|
|
1408
1411
|
def json_feed_unregistered_url
|
data/lib/commonmeta/version.rb
CHANGED
@@ -17,7 +17,7 @@ module Commonmeta
|
|
17
17
|
keywords: if subjects.present?
|
18
18
|
Array.wrap(subjects).map do |k|
|
19
19
|
parse_attributes(k, content: 'subject', first: true)
|
20
|
-
end.join(', ')
|
20
|
+
end.join(', ').capitalize
|
21
21
|
end,
|
22
22
|
language: language,
|
23
23
|
title: parse_attributes(titles, content: 'title', first: true),
|
@@ -15,7 +15,7 @@ module Commonmeta
|
|
15
15
|
'UR' => url,
|
16
16
|
'AB' => parse_attributes(descriptions, content: 'description', first: true),
|
17
17
|
'KW' => Array.wrap(subjects).map do |k|
|
18
|
-
parse_attributes(k, content: 'subject', first: true)
|
18
|
+
parse_attributes(k, content: 'subject', first: true).capitalize
|
19
19
|
end.presence,
|
20
20
|
'PY' => date['published'] && date['published'].split('-').first,
|
21
21
|
'PB' => publisher['name'],
|
@@ -19,7 +19,7 @@ module Commonmeta
|
|
19
19
|
'keywords' => if subjects.present?
|
20
20
|
Array.wrap(subjects).map do |k|
|
21
21
|
parse_attributes(k, content: 'subject', first: true)
|
22
|
-
end.join(', ')
|
22
|
+
end.join(', ').capitalize
|
23
23
|
end,
|
24
24
|
'inLanguage' => language,
|
25
25
|
'contentSize' => Array.wrap(sizes).unwrap,
|
data/spec/cli_spec.rb
CHANGED
@@ -342,6 +342,15 @@ describe Commonmeta::CLI do
|
|
342
342
|
end
|
343
343
|
|
344
344
|
describe "json_feed", vcr: true do
|
345
|
+
it "json_feed_unregistered" do
|
346
|
+
expect { subject.json_feed_unregistered }.to output(/031faba3-3a6e-49d1-a540-26523be2fd09/).to_stdout
|
347
|
+
end
|
348
|
+
|
349
|
+
it "json_feed_not_indexed" do
|
350
|
+
input = "2023-01-01"
|
351
|
+
expect { subject.json_feed_not_indexed input }.to output(/ab58e412-06eb-42b7-b81a-d340825b9d48/).to_stdout
|
352
|
+
end
|
353
|
+
|
345
354
|
it "json_feed_by_blog" do
|
346
355
|
input = "tyfqw20"
|
347
356
|
expect { subject.json_feed_by_blog input }.to output(/3e1278f6-e7c0-43e1-bb54-6829e1344c0d/).to_stdout
|