commonmeta-ruby 3.7.2 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish.yml +23 -0
  3. data/Gemfile.lock +30 -29
  4. data/bin/commonmeta +1 -1
  5. data/docs/.gitignore +1 -0
  6. data/docs/_publish.yml +4 -0
  7. data/docs/_quarto.yml +46 -0
  8. data/docs/_site/favicon.ico +0 -0
  9. data/docs/_site/images/icon.png +0 -0
  10. data/docs/_site/index.html +947 -0
  11. data/docs/_site/readers/bibtex_reader.html +802 -0
  12. data/docs/_site/search.json +74 -0
  13. data/docs/_site/site_libs/bootstrap/bootstrap-dark.min.css +9 -0
  14. data/docs/_site/site_libs/bootstrap/bootstrap-icons.css +2078 -0
  15. data/docs/_site/site_libs/bootstrap/bootstrap-icons.woff +0 -0
  16. data/docs/_site/site_libs/bootstrap/bootstrap.min.css +9 -0
  17. data/docs/_site/site_libs/bootstrap/bootstrap.min.js +7 -0
  18. data/docs/_site/site_libs/clipboard/clipboard.min.js +7 -0
  19. data/docs/_site/site_libs/quarto-html/anchor.min.js +9 -0
  20. data/docs/_site/site_libs/quarto-html/popper.min.js +6 -0
  21. data/docs/_site/site_libs/quarto-html/quarto-syntax-highlighting-dark.css +179 -0
  22. data/docs/_site/site_libs/quarto-html/quarto-syntax-highlighting.css +179 -0
  23. data/docs/_site/site_libs/quarto-html/quarto.js +889 -0
  24. data/docs/_site/site_libs/quarto-html/tippy.css +1 -0
  25. data/docs/_site/site_libs/quarto-html/tippy.umd.min.js +2 -0
  26. data/docs/_site/site_libs/quarto-nav/headroom.min.js +7 -0
  27. data/docs/_site/site_libs/quarto-nav/quarto-nav.js +288 -0
  28. data/docs/_site/site_libs/quarto-search/autocomplete.umd.js +3 -0
  29. data/docs/_site/site_libs/quarto-search/fuse.min.js +9 -0
  30. data/docs/_site/site_libs/quarto-search/quarto-search.js +1241 -0
  31. data/docs/_site/utils/doi_utils.html +787 -0
  32. data/docs/_site/writers/bibtex_writer.html +803 -0
  33. data/docs/favicon.ico +0 -0
  34. data/docs/images/icon.png +0 -0
  35. data/docs/index.qmd +83 -0
  36. data/docs/readers/bibtex_reader.ipynb +37 -0
  37. data/docs/theme.scss +7 -0
  38. data/docs/utils/doi_utils.ipynb +28 -0
  39. data/docs/writers/bibtex_writer.ipynb +39 -0
  40. data/lib/commonmeta/cli.rb +5 -5
  41. data/lib/commonmeta/crossref_utils.rb +7 -1
  42. data/lib/commonmeta/doi_utils.rb +5 -0
  43. data/lib/commonmeta/metadata.rb +66 -62
  44. data/lib/commonmeta/readers/json_feed_reader.rb +15 -5
  45. data/lib/commonmeta/version.rb +1 -1
  46. data/spec/cli_spec.rb +2 -2
  47. data/spec/doi_utils_spec.rb +14 -0
  48. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/json_feed/json_feed_blog_slug.yml +71 -0
  49. data/spec/readers/json_feed_reader_spec.rb +40 -8
  50. data/spec/writers/crossref_xml_writer_spec.rb +25 -8
  51. metadata +40 -3
data/docs/favicon.ico ADDED
Binary file
Binary file
data/docs/index.qmd ADDED
@@ -0,0 +1,83 @@
1
+ ---
2
+ title: Guide
3
+ ---
4
+
5
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5785519.svg)](https://doi.org/10.5281/zenodo.5785519)
6
+ [![Gem Version](https://badge.fury.io/rb/commonmeta-ruby.svg)](https://badge.fury.io/rb/commonmeta-ruby)
7
+ ![GitHub](https://img.shields.io/github/license/front-matter/commonmeta-ruby?logo=MIT)
8
+
9
+ commonmeta-ruby is a Ruby gem and command-line utility for the conversion of scholarly metadata, including [schema.org](https://schema.org). Based on the [bolognese](https://github.com/datacite/bolognese) gem, but using [commonmeta](https://commonmeta.org) as the intermediate format, and supporting additional metadata formats. A Python version is available at [commonmeta-py](https://github.com/front-matter/commonmeta-py).
10
+
11
+ ## Installation
12
+
13
+ Requires Ruby 3.0 or later (Ruby 2.x [has reached its end of life](https://endoflife.date/ruby) March 2023). Then add the following to your `Gemfile` to install the
14
+ latest version:
15
+
16
+ ```
17
+ gem 'commonmeta-ruby'
18
+ ```
19
+
20
+ Then run `bundle install` to install into your environment.
21
+
22
+ You can also install the gem system-wide in the usual way:
23
+
24
+ ```
25
+ gem install commonmeta-ruby
26
+ ```
27
+
28
+ ## Commands
29
+
30
+ Run the `commonmeta` command with either an identifier (DOI or URL) or filename:
31
+
32
+ ```
33
+ commonmeta https://doi.org/10.7554/elife.01567
34
+ ```
35
+
36
+ ```
37
+ commonmeta example.xml
38
+ ```
39
+
40
+ commonmeta can read BibTeX files (file extension `.bib`), RIS files (file extension `.ris`), Crossref files (file extension `.xml`), DataCite files and CSL-JSON files.
41
+
42
+ The input format (e.g. Crossref or BibteX) is automatically detected, but
43
+ you can also provide the format with the `--from` or `-f` flag. The supported
44
+ input formats are listed in the table above.
45
+
46
+ The output format is determined by the `--to` or `-t` flag, and defaults to `schema_org`.
47
+
48
+ Show all commands with `commonmeta help`:
49
+
50
+ ```
51
+ Commands:
52
+ commonmeta # convert metadata
53
+ commonmeta --version, -v # print the version
54
+ commonmeta help [COMMAND] # Describe available commands or one specific command
55
+ ```
56
+
57
+ ## Errors
58
+
59
+ Errors are returned to STDOUT.
60
+
61
+ All input is validated against the commonmeta JSON schema.
62
+
63
+ ## Supported Metadata Formats
64
+
65
+ commonmeta-ruby reads and/or writes these metadata formats:
66
+
67
+ | Format | Name | Content Type | Read | Write |
68
+ | ------ | ---- | ------------ | ---- | ----- |
69
+ | [Commonmeta](https://commonmeta.org) | commonmeta | application/vnd.commonmeta+json | yes | yes |
70
+ | [CrossRef Unixref XML](https://www.crossref.org/schema/documentation/unixref1.1/unixref1.1.html) | crossref | application/vnd.crossref.unixref+xml | yes | yes |
71
+ | [Crossref](https://api.crossref.org) | crossref | application/vnd.crossref+json | yes | no |
72
+ | [DataCite](https://api.datacite.org/) | datacite | application/vnd.datacite.datacite+json | yes | yes |
73
+ | [Schema.org (in JSON-LD)](http://schema.org/) | schema_org | application/vnd.schemaorg.ld+json | yes | yes |
74
+ | [RDF XML](http://www.w3.org/TR/rdf-syntax-grammar/) | rdf_xml | application/rdf+xml | no | yes |
75
+ | [RDF Turtle](http://www.w3.org/TeamSubmission/turtle/) | turtle | text/turtle | no | yes |
76
+ | [CSL-JSON](https://citationstyles.org/) | csl | application/vnd.citationstyles.csl+json | yes | yes |
77
+ | [Formatted text citation](https://citationstyles.org/) | citation | text/x-bibliography | no | yes |
78
+ | [Codemeta](https://codemeta.github.io/) | codemeta | application/vnd.codemeta.ld+json | yes | yes |
79
+ | [Citation File Format (CFF)](https://citation-file-format.github.io/) | cff | application/vnd.cff+yaml | yes | yes |
80
+ | [JATS](https://jats.nlm.nih.gov/) | jats | application/vnd.jats+xml | no | yes |
81
+ | [CSV](https://en.wikipedia.org/wiki/Comma-separated_values) | csv | text/csv | no | yes |
82
+ | [BibTex](http://en.wikipedia.org/wiki/BibTeX) | bibtex | application/x-bibtex | yes | yes |
83
+ | [RIS](http://en.wikipedia.org/wiki/RIS_(file_format)) | ris | application/x-research-info-systems | yes | yes |
@@ -0,0 +1,37 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "raw",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: BibTex Reader\n",
9
+ "description: |\n",
10
+ " This notebook shows how to read metadata in BibTex format.\n",
11
+ "---"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {},
17
+ "source": [
18
+ "## Fetch the metadata"
19
+ ]
20
+ }
21
+ ],
22
+ "metadata": {
23
+ "kernelspec": {
24
+ "display_name": "Ruby 3.2.2",
25
+ "language": "ruby",
26
+ "name": "ruby"
27
+ },
28
+ "language_info": {
29
+ "file_extension": ".rb",
30
+ "mimetype": "application/x-ruby",
31
+ "name": "ruby",
32
+ "version": "3.2.2"
33
+ }
34
+ },
35
+ "nbformat": 4,
36
+ "nbformat_minor": 2
37
+ }
data/docs/theme.scss ADDED
@@ -0,0 +1,7 @@
1
+ /*-- scss:defaults --*/
2
+ $toc-color: #38a169;
3
+ $header-margin-bottom: 0;
4
+ $link-color: #38a169;
5
+ $link-hover-color: #276749;
6
+ $link-decoration: none;
7
+ $navbar-bg: #e5e7eb;
@@ -0,0 +1,28 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "raw",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: doi_utils\n",
9
+ "---"
10
+ ]
11
+ }
12
+ ],
13
+ "metadata": {
14
+ "kernelspec": {
15
+ "display_name": "Ruby 3.2.2",
16
+ "language": "ruby",
17
+ "name": "ruby"
18
+ },
19
+ "language_info": {
20
+ "file_extension": ".rb",
21
+ "mimetype": "application/x-ruby",
22
+ "name": "ruby",
23
+ "version": "3.2.2"
24
+ }
25
+ },
26
+ "nbformat": 4,
27
+ "nbformat_minor": 2
28
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "raw",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: BibTex Writer\n",
9
+ "description: |\n",
10
+ " This notebook shows how to generate BibTex metadata from a scholarly resource in commonmeta format generated by commonmeta-ruby.\n",
11
+ "---"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {},
17
+ "source": [
18
+ "## Fetch the metadata\n",
19
+ "\n",
20
+ "As with all commonmeta-ruby notebooks, we start by fetching metadata, in this example a journal article via its Crossref DOI, and then convert it to the commonmeta format."
21
+ ]
22
+ }
23
+ ],
24
+ "metadata": {
25
+ "kernelspec": {
26
+ "display_name": "Ruby 3.2.2",
27
+ "language": "ruby",
28
+ "name": "ruby"
29
+ },
30
+ "language_info": {
31
+ "file_extension": ".rb",
32
+ "mimetype": "application/x-ruby",
33
+ "name": "ruby",
34
+ "version": "3.2.2"
35
+ }
36
+ },
37
+ "nbformat": 4,
38
+ "nbformat_minor": 2
39
+ }
@@ -71,8 +71,8 @@ module Commonmeta
71
71
 
72
72
  desc "", "encode_by_blog"
73
73
 
74
- def encode_by_blog(blog_id)
75
- prefix = get_doi_prefix_by_blog_id(blog_id)
74
+ def encode_by_blog(blog_slug)
75
+ prefix = get_doi_prefix_by_blog_slug(blog_slug)
76
76
  return nil unless prefix.present?
77
77
  puts encode_doi(prefix)
78
78
  end
@@ -115,10 +115,10 @@ module Commonmeta
115
115
  puts get_json_feed_by_blog(id)
116
116
  end
117
117
 
118
- desc "", "json_feed_blog_id"
118
+ desc "", "json_feed_blog_slug"
119
119
 
120
- def json_feed_blog_id(id)
121
- puts get_json_feed_blog_id(id)
120
+ def json_feed_blog_slug(slug)
121
+ puts get_json_feed_blog_slug(slug)
122
122
  end
123
123
 
124
124
  desc "", "update_ghost_post"
@@ -342,11 +342,17 @@ module Commonmeta
342
342
  return xml if doi_from_url(id).blank? || url.blank?
343
343
 
344
344
  xml.doi_data do
345
- xml.doi(doi_from_url(id).downcase)
345
+ doi = doi_from_url(id).downcase
346
+ xml.doi(doi)
346
347
  xml.resource(url)
347
348
  xml.collection("property" => "text-mining") do
348
349
  xml.item do
349
350
  xml.resource(url, "mime_type" => "text/html")
351
+ if is_rogue_scholar_doi?(doi)
352
+ Array.wrap(files).each do |file|
353
+ xml.resource(file["url"], "mime_type" => file["mimeType"])
354
+ end
355
+ end
350
356
  end
351
357
  end
352
358
  end
@@ -77,5 +77,10 @@ module Commonmeta
77
77
 
78
78
  { 'id' => "https://api.crossref.org/members/#{member_id}", 'name' => name }
79
79
  end
80
+
81
+ def is_rogue_scholar_doi?(doi)
82
+ prefix = validate_prefix(doi)
83
+ %w[10.34732 10.53731 10.54900 10.57689 10.59348 10.59349 10.59350].include?(prefix)
84
+ end
80
85
  end
81
86
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: truefiles
2
2
 
3
- require_relative 'metadata_utils'
3
+ require_relative "metadata_utils"
4
4
 
5
5
  module Commonmeta
6
6
  class Metadata
@@ -10,7 +10,11 @@ module Commonmeta
10
10
  :email, :registrant
11
11
  attr_reader :doc, :page_start, :page_end
12
12
  attr_writer :id, :provider_id, :client_id, :doi, :alternate_identifiers, :contributors,
13
- :titles, :publisher, :license, :date, :volume, :url, :version, :subjects, :descriptions, :language, :sizes, :formats, :schema_version, :meta, :container, :provider, :format, :funding_references, :state, :geo_locations, :type, :additional_type, :files, :references, :related_identifiers, :related_items, :style, :locale, :archive_locations
13
+ :titles, :publisher, :license, :date, :volume, :url, :version, :subjects,
14
+ :descriptions, :language, :sizes, :formats, :schema_version, :meta, :container,
15
+ :provider, :format, :funding_references, :state, :geo_locations, :type,
16
+ :additional_type, :files, :references, :related_identifiers, :related_items,
17
+ :style, :locale, :archive_locations
14
18
 
15
19
  def initialize(options = {})
16
20
  options.symbolize_keys!
@@ -23,29 +27,29 @@ module Commonmeta
23
27
 
24
28
  # mEDRA, KISTI, JaLC and OP DOIs are found in the Crossref index
25
29
  case @from
26
- when 'medra'
27
- ra = 'mEDRA'
28
- when 'kisti'
29
- ra = 'KISTI'
30
- when 'jalc'
31
- ra = 'JaLC'
32
- when 'op'
33
- ra = 'OP'
30
+ when "medra"
31
+ ra = "mEDRA"
32
+ when "kisti"
33
+ ra = "KISTI"
34
+ when "jalc"
35
+ ra = "JaLC"
36
+ when "op"
37
+ ra = "OP"
34
38
  end
35
39
 
36
40
  # generate name for method to call dynamically
37
41
  hsh = @from.present? ? send("get_#{@from}", id: id, **options) : {}
38
- string = hsh.fetch('string', nil)
42
+ string = hsh.fetch("string", nil)
39
43
  elsif options[:input].present? && File.exist?(options[:input])
40
44
  filename = File.basename(options[:input])
41
45
  ext = File.extname(options[:input])
42
46
  if %w[.bib .ris .xml .json .cff].include?(ext)
43
47
  hsh = {
44
- 'url' => options[:url],
45
- 'state' => options[:state],
46
- 'provider_id' => options[:provider_id],
47
- 'client_id' => options[:client_id],
48
- 'files' => options[:files]
48
+ "url" => options[:url],
49
+ "state" => options[:state],
50
+ "provider_id" => options[:provider_id],
51
+ "client_id" => options[:client_id],
52
+ "files" => options[:files],
49
53
  }
50
54
  string = File.read(options[:input])
51
55
  @from = options[:from] || find_from_format(string: string, ext: ext)
@@ -55,14 +59,14 @@ module Commonmeta
55
59
  end
56
60
  else
57
61
  hsh = {
58
- 'url' => options[:url],
59
- 'state' => options[:state],
60
- 'provider_id' => options[:provider_id],
61
- 'client_id' => options[:client_id],
62
- 'files' => options[:files],
63
- 'contributors' => options[:contributors],
64
- 'titles' => options[:titles],
65
- 'publisher' => options[:publisher]
62
+ "url" => options[:url],
63
+ "state" => options[:state],
64
+ "provider_id" => options[:provider_id],
65
+ "client_id" => options[:client_id],
66
+ "files" => options[:files],
67
+ "contributors" => options[:contributors],
68
+ "titles" => options[:titles],
69
+ "publisher" => options[:publisher],
66
70
  }
67
71
  string = options[:input]
68
72
  @from = options[:from] || find_from_format(string: string)
@@ -70,7 +74,7 @@ module Commonmeta
70
74
 
71
75
  # make sure input is encoded as utf8
72
76
  if string.present? && string.is_a?(String)
73
- dup_string = string.dup.force_encoding('UTF-8').encode!
77
+ dup_string = string.dup.force_encoding("UTF-8").encode!
74
78
  end
75
79
  @string = dup_string
76
80
 
@@ -81,11 +85,11 @@ module Commonmeta
81
85
  @sandbox = options[:sandbox]
82
86
 
83
87
  # options that come from the datacite database
84
- @url = hsh.to_h['url'].presence || options[:url].presence
85
- @state = hsh.to_h['state'].presence
86
- @provider_id = hsh.to_h['provider_id'].presence
87
- @client_id = hsh.to_h['client_id'].presence
88
- @files = hsh.to_h['files'].presence
88
+ @url = hsh.to_h["url"].presence || options[:url].presence
89
+ @state = hsh.to_h["state"].presence
90
+ @provider_id = hsh.to_h["provider_id"].presence
91
+ @client_id = hsh.to_h["client_id"].presence
92
+ @files = hsh.to_h["files"].presence
89
93
 
90
94
  # options that come from the cli, needed
91
95
  # for crossref doi registration
@@ -125,23 +129,23 @@ module Commonmeta
125
129
  end
126
130
 
127
131
  def id
128
- @id ||= meta.fetch('id', nil)
132
+ @id ||= meta.fetch("id", nil)
129
133
  end
130
134
 
131
135
  def doi
132
- @doi ||= meta.fetch('doi', nil)
136
+ @doi ||= meta.fetch("doi", nil)
133
137
  end
134
138
 
135
139
  def provider_id
136
- @provider_id ||= meta.fetch('provider_id', nil)
140
+ @provider_id ||= meta.fetch("provider_id", nil)
137
141
  end
138
142
 
139
143
  def client_id
140
- @client_id ||= meta.fetch('client_id', nil)
144
+ @client_id ||= meta.fetch("client_id", nil)
141
145
  end
142
146
 
143
147
  def exists?
144
- (@state || meta.fetch('state', nil)) != 'not_found'
148
+ (@state || meta.fetch("state", nil)) != "not_found"
145
149
  end
146
150
 
147
151
  def valid?
@@ -151,111 +155,111 @@ module Commonmeta
151
155
  # Catch errors in the reader
152
156
  # Then validate against JSON schema for Commonmeta
153
157
  def errors
154
- meta.fetch('errors', nil) || json_schema_errors
158
+ meta.fetch("errors", nil) || json_schema_errors
155
159
  end
156
160
 
157
161
  def descriptions
158
- @descriptions ||= meta.fetch('descriptions', nil)
162
+ @descriptions ||= meta.fetch("descriptions", nil)
159
163
  end
160
164
 
161
165
  def license
162
- @license ||= meta.fetch('license', nil)
166
+ @license ||= meta.fetch("license", nil)
163
167
  end
164
168
 
165
169
  def subjects
166
- @subjects ||= meta.fetch('subjects', nil)
170
+ @subjects ||= meta.fetch("subjects", nil)
167
171
  end
168
172
 
169
173
  def language
170
- @language ||= meta.fetch('language', nil)
174
+ @language ||= meta.fetch("language", nil)
171
175
  end
172
176
 
173
177
  def sizes
174
- @sizes ||= meta.fetch('sizes', nil)
178
+ @sizes ||= meta.fetch("sizes", nil)
175
179
  end
176
180
 
177
181
  def formats
178
- @formats ||= meta.fetch('formats', nil)
182
+ @formats ||= meta.fetch("formats", nil)
179
183
  end
180
184
 
181
185
  def schema_version
182
- @schema_version ||= meta.fetch('schema_version', nil)
186
+ @schema_version ||= meta.fetch("schema_version", nil)
183
187
  end
184
188
 
185
189
  def funding_references
186
- @funding_references ||= meta.fetch('funding_references', nil)
190
+ @funding_references ||= meta.fetch("funding_references", nil)
187
191
  end
188
192
 
189
193
  def references
190
- @references ||= meta.fetch('references', nil)
194
+ @references ||= meta.fetch("references", nil)
191
195
  end
192
196
 
193
197
  def related_identifiers
194
- @related_identifiers ||= meta.fetch('related_identifiers', nil)
198
+ @related_identifiers ||= meta.fetch("related_identifiers", nil)
195
199
  end
196
200
 
197
201
  def related_items
198
- @related_items ||= meta.fetch('related_items', nil)
202
+ @related_items ||= meta.fetch("related_items", nil)
199
203
  end
200
204
 
201
205
  def url
202
- @url ||= meta.fetch('url', nil)
206
+ @url ||= meta.fetch("url", nil)
203
207
  end
204
208
 
205
209
  def version
206
- @version ||= meta.fetch('version', nil)
210
+ @version ||= meta.fetch("version", nil)
207
211
  end
208
212
 
209
213
  def container
210
- @container ||= meta.fetch('container', nil)
214
+ @container ||= meta.fetch("container", nil)
211
215
  end
212
216
 
213
217
  def geo_locations
214
- @geo_locations ||= meta.fetch('geo_locations', nil)
218
+ @geo_locations ||= meta.fetch("geo_locations", nil)
215
219
  end
216
220
 
217
221
  def date
218
- @date ||= meta.fetch('date', nil)
222
+ @date ||= meta.fetch("date", nil)
219
223
  end
220
224
 
221
225
  def publisher
222
- @publisher ||= meta.fetch('publisher', nil)
226
+ @publisher ||= meta.fetch("publisher", nil)
223
227
  end
224
228
 
225
229
  def alternate_identifiers
226
- @alternate_identifiers ||= meta.fetch('alternate_identifiers', nil)
230
+ @alternate_identifiers ||= meta.fetch("alternate_identifiers", nil)
227
231
  end
228
232
 
229
233
  def files
230
- @files ||= meta.fetch('files', nil)
234
+ @files ||= meta.fetch("files", nil)
231
235
  end
232
236
 
233
237
  def provider
234
- @provider ||= meta.fetch('provider', nil)
238
+ @provider ||= meta.fetch("provider", nil)
235
239
  end
236
240
 
237
241
  def state
238
- @state ||= meta.fetch('state', nil)
242
+ @state ||= meta.fetch("state", nil)
239
243
  end
240
244
 
241
245
  def type
242
- @type ||= meta.fetch('type', nil)
246
+ @type ||= meta.fetch("type", nil)
243
247
  end
244
248
 
245
249
  def additional_type
246
- @additional_type ||= meta.fetch('additional_type', nil)
250
+ @additional_type ||= meta.fetch("additional_type", nil)
247
251
  end
248
252
 
249
253
  def titles
250
- @titles ||= meta.fetch('titles', nil)
254
+ @titles ||= meta.fetch("titles", nil)
251
255
  end
252
256
 
253
257
  def contributors
254
- @contributors ||= meta.fetch('contributors', nil)
258
+ @contributors ||= meta.fetch("contributors", nil)
255
259
  end
256
260
 
257
261
  def archive_locations
258
- @archive_locations ||= meta.fetch('archive_locations', nil)
262
+ @archive_locations ||= meta.fetch("archive_locations", nil)
259
263
  end
260
264
  end
261
265
  end
@@ -69,7 +69,7 @@ module Commonmeta
69
69
  funding_references = get_funding_references(meta)
70
70
  related_identifiers = get_related_identifiers(meta)
71
71
  alternate_identifiers = [{ "alternateIdentifier" => meta["id"], "alternateIdentifierType" => "UUID" }]
72
-
72
+ files = get_files(id)
73
73
  archive_url = meta.fetch("archive_url", nil)
74
74
 
75
75
  if archive_url
@@ -99,10 +99,20 @@ module Commonmeta
99
99
  "funding_references" => funding_references.presence,
100
100
  "related_identifiers" => related_identifiers.presence,
101
101
  "alternate_identifiers" => alternate_identifiers,
102
+ "files" => files.presence,
102
103
  "archive_locations" => archive_locations,
103
104
  "state" => state }.compact.merge(read_options)
104
105
  end
105
106
 
107
+ def get_files(id)
108
+ doi = doi_from_url(id)
109
+ return nil unless is_rogue_scholar_doi?(doi)
110
+
111
+ [{ "mimeType" => "text/markdown", "url" => "https://api.rogue-scholar.org/posts/#{doi}.md" },
112
+ { "mimeType" => "application/pdf", "url" => "https://api.rogue-scholar.org/posts/#{doi}.pdf" },
113
+ { "mimeType" => "application/epub+zip", "url" => "https://api.rogue-scholar.org/posts/#{doi}.epub" }]
114
+ end
115
+
106
116
  def get_references(meta)
107
117
  # check that references resolve
108
118
  Array.wrap(meta["reference"]).reduce([]) do |sum, reference|
@@ -212,8 +222,8 @@ module Commonmeta
212
222
  blog["items"].map { |item| item["id"] }.first
213
223
  end
214
224
 
215
- def get_json_feed_blog_id(id)
216
- # get JSON Feed item by id and return blog id
225
+ def get_json_feed_blog_slug(id)
226
+ # get JSON Feed item by id and return blog slug
217
227
 
218
228
  url = json_feed_item_by_id_url(id)
219
229
  response = HTTP.get(url)
@@ -223,10 +233,10 @@ module Commonmeta
223
233
  post.to_h.dig("blog", "slug")
224
234
  end
225
235
 
226
- def get_doi_prefix_by_blog_id(blog_id)
236
+ def get_doi_prefix_by_blog_slug(blog_slug)
227
237
  # for generating a random DOI.
228
238
 
229
- url = json_feed_by_blog_url(blog_id)
239
+ url = json_feed_by_blog_url(blog_slug)
230
240
  response = HTTP.get(url)
231
241
  return nil unless response.status.success?
232
242
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.7.2'
4
+ VERSION = '3.8.0'
5
5
  end
data/spec/cli_spec.rb CHANGED
@@ -379,9 +379,9 @@ describe Commonmeta::CLI do
379
379
  expect { subject.json_feed_by_blog input }.to output(/3749f8c4-1ba7-4e51-9dd6-9d9551ad451a/).to_stdout
380
380
  end
381
381
 
382
- it "json_feed_blog_id" do
382
+ it "json_feed_blog_slug" do
383
383
  input = "01a92f9a-f8e0-442b-86e2-11530d9d5635"
384
- expect { subject.json_feed_blog_id input }.to output(/eve/).to_stdout
384
+ expect { subject.json_feed_blog_slug input }.to output(/eve/).to_stdout
385
385
  end
386
386
  end
387
387
  end
@@ -315,4 +315,18 @@ describe Commonmeta::Metadata, vcr: true do
315
315
  expect(response).to eq('10.5061')
316
316
  end
317
317
  end
318
+
319
+ context 'is_rogue_scholar_doi' do
320
+ it 'rogue scholar doi' do
321
+ doi = '10.53731/cjx855h-hn5jtq8'
322
+ response = subject.is_rogue_scholar_doi?(doi)
323
+ expect(response).to be true
324
+ end
325
+
326
+ it 'not a rogue scholar doi' do
327
+ doi = '10.1371/journal.pone.0000030'
328
+ response = subject.is_rogue_scholar_doi?(doi)
329
+ expect(response).to be false
330
+ end
331
+ end
318
332
  end