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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb3a97138b6b57a503b29202613fd81d5124c66ef2523ba9ef7cccccb78d7ff8
4
- data.tar.gz: 0b9f6d3b310604ff2bb567b0ae13ae025d9c954c77669d9adec2f3e1bd36f307
3
+ metadata.gz: b549fc46c70c5962ee3c971968771a6e5f13124eb89b03aab36228afc94c01fe
4
+ data.tar.gz: 1545d0de4e821265cc19bb744456d025f6bc14ea52c19cbae2585a1d501501a4
5
5
  SHA512:
6
- metadata.gz: 8262107294fc3be73c4b39ed45a662f1cd0e6a98702deb5bbc65fe91b8e9a31e890d33e38246c5852232be35746ce40d3cc9c77a9314a979dbf7c659b8826b56
7
- data.tar.gz: 5d68d6084d2a0257147346cc68837ed64955691141dcef7568fa7de3f5fffcd9b7573201ab9b4e26bbd0c6fcb7aee6cc4abadaf766c9344da5383e42dcbf2223
6
+ metadata.gz: 3d7a785d1fdbf3bd226a64f489ef12e37cb474fe0334c894e98c0a86b90fba23d02d937eed3bc4f4e710791209556ab2ece950e50491d48874e128e95f62c44e
7
+ data.tar.gz: cad955e4ba4066a42ff821f03437cfe09fb926c283785050d34682cc95e676d89d608f03ca63c18574d012e5fcad168c5f289cd7d465f525846c877e91368635
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.2.12)
4
+ commonmeta-ruby (3.2.14)
5
5
  activesupport (>= 4.2.5, < 8.0)
6
6
  addressable (~> 2.8.1, < 2.8.2)
7
7
  base32-url (>= 0.7.0, < 1)
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 json_feed_updated json_feed_unregistered json_feed_by_blog)).empty?
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
@@ -86,10 +86,10 @@ module Commonmeta
86
86
  puts get_json_feed_unregistered
87
87
  end
88
88
 
89
- desc "", "json_feed_updated"
89
+ desc "", "json_feed_not_indexed"
90
90
 
91
- def json_feed_updated
92
- puts get_json_feed_updated
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"].titleize)
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
- # convert UUIDs into base32 encoded strings, as item_number can only be 32 characters long (UUIDv4 is 36 characters long)
268
- alternate_identifier["alternateIdentifier"] = Base32::URL.encode_uuid(alternate_identifier["alternateIdentifier"], split: 7, checksum: true) if alternate_identifier["alternateIdentifierType"] == "UUID"
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.fetch("tags", nil)).reduce([]) do |sum, subject|
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"] }.join('\n')
99
+ posts.map { |post| post["uuid"] }.first
100
100
  end
101
101
 
102
- def get_json_feed_updated
103
- # get JSON Feed items updated since last check
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 = json_feed_updated_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"] }.join('\n')
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"] }.join('\n')
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.downcase.split(', ') if subjects.is_a?(String)
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
@@ -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).downcase,
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).downcase,
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).downcase }]
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 json_feed_updated_url
1405
- "https://rogue-scholar.org/api/posts/updated"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.2.12'
4
+ VERSION = '3.2.14'
5
5
  end
@@ -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