commonmeta-ruby 3.0.9 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -3
  3. data/Gemfile.lock +42 -43
  4. data/commonmeta.gemspec +1 -2
  5. data/lib/commonmeta/crossref_utils.rb +4 -7
  6. data/lib/commonmeta/metadata.rb +4 -10
  7. data/lib/commonmeta/metadata_utils.rb +2 -0
  8. data/lib/commonmeta/readers/json_post_reader.rb +78 -0
  9. data/lib/commonmeta/utils.rb +19 -0
  10. data/lib/commonmeta/version.rb +1 -1
  11. data/lib/commonmeta.rb +0 -1
  12. data/spec/author_utils_spec.rb +10 -0
  13. data/spec/cli_spec.rb +21 -1
  14. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/convert_file/crossref/to_crossref_xml.yml +107 -0
  15. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/convert_file/crossref_xml/to_crossref_xml.yml +52 -0
  16. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/convert_file/crossref_xml/to_crossref_xml_refresh.yml +107 -0
  17. data/spec/fixtures/vcr_cassettes/Commonmeta_CLI/convert_from_id/schema_org/to_crossref_xml.yml +2189 -0
  18. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_item_metadata/blogger_post.yml +94 -0
  19. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_item_metadata/ghost_post.yml +117 -0
  20. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_item_metadata/ghost_post_with_doi.yml +117 -0
  21. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_item_metadata/jekyll_post.yml +170 -0
  22. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_item_metadata/wordpress_post.yml +163 -0
  23. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_post_metadata/blogger_post.yml +94 -0
  24. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_post_metadata/ghost_post_with_doi.yml +117 -0
  25. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_post_metadata/jekyll_post.yml +87 -0
  26. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_json_post_metadata/wordpress_post.yml +163 -0
  27. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_link/license.yml +221 -0
  28. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/get_link/url.yml +221 -0
  29. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_item_from_rogue_scholar_with_doi.yml +163 -0
  30. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_item_from_upstream_blog.yml +243 -0
  31. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_post_from_rogue_scholar_with_doi.yml +163 -0
  32. data/spec/fixtures/vcr_cassettes/Commonmeta_Metadata/write_metadata_as_crossref/json_post_from_upstream_blog.yml +243 -0
  33. data/spec/metadata_spec.rb +1 -1
  34. data/spec/readers/datacite_reader_spec.rb +1 -1
  35. data/spec/readers/json_post_reader_spec.rb +89 -0
  36. data/spec/utils_spec.rb +330 -314
  37. data/spec/writers/crossref_xml_writer_spec.rb +183 -137
  38. metadata +24 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20990b6d7886c09275212fc7d92b3a0450a38e9f6f903f011ad560c58dce13b5
4
- data.tar.gz: 768648c8a29a23744b6f5f371e5950af7e7a038864d7c4b9686ae533a2441e81
3
+ metadata.gz: 1ff3685620f0d6399524eac22d162f7b32391fa1424783a30e6c2f914d30deea
4
+ data.tar.gz: bf986a52084af3c28fb163a59022b1ede266b37b77bfd0bf8365c35fd98893b3
5
5
  SHA512:
6
- metadata.gz: c7d38f03cc79506b8dc32c39fcbe0d353c0da9fde8da49c7e73c4c5bcf513dbb80129a39533a5b69a11bd88b12a257e8901050e5956be6b52f9c0e774f04a8f8
7
- data.tar.gz: 12a2a786ae08af6d8d796886eb183b415e37fefa43cd98c7407acf14ca7afe56f7b448aaa2c463e1706e47e9b1bff9fcfae89736e1e3376908af8ef93dcfe5b8
6
+ metadata.gz: 447cc3b60622046224caf62ee2afa70f35f1b47c229c7407f126a3efcc6815cf129386590c6f1114c894111b657326fc35b442427c84907058bd809236a5afff
7
+ data.tar.gz: 69715e0926e03fc2441b8236a6e6beb0440b69dad8bde707f8d097a3d1922b71b3c80ac4c6286d8fc1fa5d489cc29be02250be6c4a6aadd0747d91bef1251b78
data/.gitignore CHANGED
@@ -10,9 +10,6 @@
10
10
  /test/version_tmp/
11
11
  /tmp/
12
12
 
13
- # Used by dotenv library to load environment variables.
14
- .env
15
-
16
13
  ## Specific to RubyMotion:
17
14
  .dat*
18
15
  .repl_history
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.0.9)
4
+ commonmeta-ruby (3.2.0)
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)
@@ -9,12 +9,11 @@ PATH
9
9
  builder (~> 3.2, >= 3.2.4)
10
10
  citeproc-ruby (~> 2.0)
11
11
  csl-styles (~> 2.0)
12
- dotenv (~> 2.1, >= 2.1.1)
13
12
  edtf (~> 3.0, >= 3.0.4)
14
13
  gender_detector (~> 2.0)
15
14
  http (~> 5.1, >= 5.1.1)
16
15
  json-ld-preloaded (~> 3.2, >= 3.2.2)
17
- json_schemer (~> 0.2.23)
16
+ json_schemer (~> 1.0.1)
18
17
  jsonlint (~> 0.3.0)
19
18
  loofah (~> 2.19)
20
19
  namae (~> 1.0)
@@ -26,7 +25,7 @@ PATH
26
25
  GEM
27
26
  remote: https://rubygems.org/
28
27
  specs:
29
- activesupport (7.0.4.3)
28
+ activesupport (7.0.5)
30
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
31
30
  i18n (>= 1.6, < 2)
32
31
  minitest (>= 5.1)
@@ -58,15 +57,12 @@ GEM
58
57
  docile (1.4.0)
59
58
  domain_name (0.5.20190701)
60
59
  unf (>= 0.0.5, < 1.0.0)
61
- dotenv (2.8.1)
62
- ebnf (2.3.2)
60
+ ebnf (2.3.3)
63
61
  htmlentities (~> 4.3)
64
62
  rdf (~> 3.2)
65
63
  scanf (~> 1.0)
66
64
  sxp (~> 1.2)
67
65
  unicode-types (~> 1.8)
68
- ecma-re-validator (0.4.0)
69
- regexp_parser (~> 2.2)
70
66
  edtf (3.1.1)
71
67
  activesupport (>= 3.0, < 8.0)
72
68
  ffi (1.15.5)
@@ -74,9 +70,8 @@ GEM
74
70
  ffi (>= 1.0.0)
75
71
  rake
76
72
  gender_detector (2.0.0)
77
- haml (6.1.1)
78
- temple (>= 0.8.2)
79
- thor
73
+ haml (5.2.2)
74
+ temple (>= 0.8.0)
80
75
  tilt
81
76
  hana (1.3.7)
82
77
  hashdiff (1.0.1)
@@ -89,25 +84,24 @@ GEM
89
84
  http-cookie (1.0.5)
90
85
  domain_name (~> 0.5)
91
86
  http-form_data (2.3.0)
92
- i18n (1.12.0)
87
+ i18n (1.14.0)
93
88
  concurrent-ruby (~> 1.0)
94
89
  json (2.6.3)
95
- json-canonicalization (0.3.1)
96
- json-ld (3.2.3)
90
+ json-canonicalization (0.3.2)
91
+ json-ld (3.2.5)
97
92
  htmlentities (~> 4.3)
98
- json-canonicalization (~> 0.3)
93
+ json-canonicalization (~> 0.3, >= 0.3.2)
99
94
  link_header (~> 0.0, >= 0.0.8)
100
95
  multi_json (~> 1.15)
101
- rack (~> 2.2)
102
- rdf (~> 3.2, >= 3.2.9)
96
+ rack (>= 2.2, < 4)
97
+ rdf (~> 3.2, >= 3.2.10)
103
98
  json-ld-preloaded (3.2.2)
104
99
  json-ld (~> 3.2)
105
100
  rdf (~> 3.2)
106
- json_schemer (0.2.24)
107
- ecma-re-validator (~> 0.3)
101
+ json_schemer (1.0.1)
108
102
  hana (~> 1.3)
109
103
  regexp_parser (~> 2.0)
110
- uri_template (~> 0.7)
104
+ simpleidn (~> 0.2)
111
105
  jsonlint (0.3.0)
112
106
  oj (~> 3)
113
107
  optimist (~> 3)
@@ -116,19 +110,19 @@ GEM
116
110
  llhttp-ffi (0.4.0)
117
111
  ffi-compiler (~> 1.0)
118
112
  rake (~> 13.0)
119
- loofah (2.20.0)
113
+ loofah (2.21.3)
120
114
  crass (~> 1.0.2)
121
- nokogiri (>= 1.5.9)
115
+ nokogiri (>= 1.12.0)
122
116
  matrix (0.4.2)
123
117
  minitest (5.18.0)
124
118
  multi_json (1.15.0)
125
119
  namae (1.1.1)
126
- nokogiri (1.14.2-arm64-darwin)
120
+ nokogiri (1.15.2-arm64-darwin)
127
121
  racc (~> 1.4)
128
- oj (3.14.2)
122
+ oj (3.15.0)
129
123
  optimist (3.0.1)
130
- parallel (1.22.1)
131
- parser (3.2.2.0)
124
+ parallel (1.23.0)
125
+ parser (3.2.2.1)
132
126
  ast (~> 2.4.1)
133
127
  postrank-uri (1.1)
134
128
  addressable (>= 2.4.0)
@@ -136,23 +130,24 @@ GEM
136
130
  public_suffix (>= 4.0.0, < 5)
137
131
  public_suffix (4.0.7)
138
132
  racc (1.6.2)
139
- rack (2.2.6.4)
133
+ rack (3.0.7)
140
134
  rack-test (2.1.0)
141
135
  rack (>= 1.3)
142
136
  rainbow (3.1.1)
143
137
  rake (13.0.6)
144
- rdf (3.2.9)
138
+ rdf (3.2.10)
145
139
  link_header (~> 0.0, >= 0.0.8)
146
140
  rdf-aggregate-repo (3.2.1)
147
141
  rdf (~> 3.2)
148
- rdf-rdfa (3.2.1)
142
+ rdf-rdfa (3.2.2)
149
143
  haml (>= 5.2, < 7)
150
144
  htmlentities (~> 4.3)
151
145
  rdf (~> 3.2)
152
146
  rdf-aggregate-repo (~> 3.2)
153
147
  rdf-vocab (~> 3.2)
154
148
  rdf-xsd (~> 3.2)
155
- rdf-rdfxml (3.2.0)
149
+ rdf-rdfxml (3.2.1)
150
+ haml (~> 5.2)
156
151
  htmlentities (~> 4.3)
157
152
  rdf (~> 3.2)
158
153
  rdf-rdfa (~> 3.2)
@@ -160,20 +155,20 @@ GEM
160
155
  rdf-turtle (3.2.1)
161
156
  ebnf (~> 2.3)
162
157
  rdf (~> 3.2)
163
- rdf-vocab (3.2.4)
158
+ rdf-vocab (3.2.6)
164
159
  rdf (~> 3.2, >= 3.2.4)
165
160
  rdf-xsd (3.2.1)
166
161
  rdf (~> 3.2)
167
162
  rexml (~> 3.2)
168
- regexp_parser (2.7.0)
163
+ regexp_parser (2.8.0)
169
164
  rexml (3.2.5)
170
165
  rspec (3.12.0)
171
166
  rspec-core (~> 3.12.0)
172
167
  rspec-expectations (~> 3.12.0)
173
168
  rspec-mocks (~> 3.12.0)
174
- rspec-core (3.12.1)
169
+ rspec-core (3.12.2)
175
170
  rspec-support (~> 3.12.0)
176
- rspec-expectations (3.12.2)
171
+ rspec-expectations (3.12.3)
177
172
  diff-lcs (>= 1.2.0, < 2.0)
178
173
  rspec-support (~> 3.12.0)
179
174
  rspec-mocks (3.12.5)
@@ -183,7 +178,7 @@ GEM
183
178
  rspec-xsd (0.1.0)
184
179
  nokogiri (~> 1.6)
185
180
  rspec (~> 3)
186
- rubocop (1.49.0)
181
+ rubocop (1.52.0)
187
182
  json (~> 2.3)
188
183
  parallel (~> 1.10)
189
184
  parser (>= 3.2.0.0)
@@ -193,18 +188,21 @@ GEM
193
188
  rubocop-ast (>= 1.28.0, < 2.0)
194
189
  ruby-progressbar (~> 1.7)
195
190
  unicode-display_width (>= 2.4.0, < 3.0)
196
- rubocop-ast (1.28.0)
191
+ rubocop-ast (1.29.0)
197
192
  parser (>= 3.2.1.0)
198
- rubocop-capybara (2.17.1)
193
+ rubocop-capybara (2.18.0)
199
194
  rubocop (~> 1.41)
200
- rubocop-performance (1.16.0)
195
+ rubocop-factory_bot (2.23.1)
196
+ rubocop (~> 1.33)
197
+ rubocop-performance (1.18.0)
201
198
  rubocop (>= 1.7.0, < 2.0)
202
199
  rubocop-ast (>= 0.4.0)
203
200
  rubocop-rake (0.6.0)
204
201
  rubocop (~> 1.0)
205
- rubocop-rspec (2.19.0)
202
+ rubocop-rspec (2.22.0)
206
203
  rubocop (~> 1.33)
207
204
  rubocop-capybara (~> 2.17)
205
+ rubocop-factory_bot (~> 2.22)
208
206
  ruby-progressbar (1.13.0)
209
207
  scanf (1.0.0)
210
208
  simplecov (0.22.0)
@@ -213,11 +211,13 @@ GEM
213
211
  simplecov_json_formatter (~> 0.1)
214
212
  simplecov-html (0.12.3)
215
213
  simplecov_json_formatter (0.1.4)
216
- sxp (1.2.3)
214
+ simpleidn (0.2.1)
215
+ unf (~> 0.1.4)
216
+ sxp (1.2.4)
217
217
  matrix (~> 0.4)
218
218
  rdf (~> 3.2)
219
- temple (0.10.0)
220
- thor (1.2.1)
219
+ temple (0.10.2)
220
+ thor (1.2.2)
221
221
  tilt (2.1.0)
222
222
  tzinfo (2.0.6)
223
223
  concurrent-ruby (~> 1.0)
@@ -226,7 +226,6 @@ GEM
226
226
  unf_ext (0.0.8.2)
227
227
  unicode-display_width (2.4.2)
228
228
  unicode-types (1.8.0)
229
- uri_template (0.7.0)
230
229
  vcr (6.1.0)
231
230
  webmock (3.18.1)
232
231
  addressable (>= 2.8.0)
data/commonmeta.gemspec CHANGED
@@ -25,13 +25,12 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency 'builder', '~> 3.2', '>= 3.2.4'
26
26
  s.add_dependency 'citeproc-ruby', '~> 2.0'
27
27
  s.add_dependency 'csl-styles', '~> 2.0'
28
- s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
29
28
  s.add_dependency 'edtf', '~> 3.0', '>= 3.0.4'
30
29
  s.add_dependency 'gender_detector', '~> 2.0'
31
30
  s.add_dependency 'http', '~> 5.1', '>= 5.1.1'
32
31
  s.add_dependency 'json-ld-preloaded', '~> 3.2', '>= 3.2.2'
33
32
  s.add_dependency 'jsonlint', '~> 0.3.0'
34
- s.add_dependency 'json_schemer', '~> 0.2.23'
33
+ s.add_dependency 'json_schemer', '~> 1.0.1'
35
34
  s.add_dependency 'loofah', '~> 2.19'
36
35
  s.add_dependency 'namae', '~> 1.0'
37
36
  s.add_dependency 'postrank-uri', '~> 1.1'
@@ -2,9 +2,6 @@
2
2
 
3
3
  module Commonmeta
4
4
  module CrossrefUtils
5
- # To configure the writing of Crossref metadata, use environmental
6
- # variables CROSSREF_DEPOSITOR_NAME, CROSSREF_DEPOSITOR_EMAIL and CROSSREF_REGISTRANT,
7
- # e.g. in a .env file
8
5
  def write_crossref_xml
9
6
  @crossref_xml ||= Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
10
7
  xml.doi_batch(crossref_root_attributes) do
@@ -13,10 +10,10 @@ module Commonmeta
13
10
  xml.doi_batch_id(SecureRandom.uuid)
14
11
  xml.timestamp(Time.now.utc.strftime('%Y%m%d%H%M%S'))
15
12
  xml.depositor do
16
- xml.depositor_name(ENV.fetch('CROSSREF_DEPOSITOR_NAME', nil))
17
- xml.email_address(ENV.fetch('CROSSREF_DEPOSITOR_EMAIL', nil))
13
+ xml.depositor_name(depositor)
14
+ xml.email_address(email)
18
15
  end
19
- xml.registrant(ENV.fetch('CROSSREF_REGISTRANT', nil))
16
+ xml.registrant(registrant)
20
17
  end
21
18
  xml.body do
22
19
  insert_crossref_work(xml)
@@ -133,7 +130,7 @@ module Commonmeta
133
130
 
134
131
  def insert_citation_list(xml)
135
132
  xml.citation_list do
136
- references.each do |ref|
133
+ Array.wrap(references).each do |ref|
137
134
  xml.citation('key' => ref['key']) do
138
135
  xml.journal_article(ref['journal_title'])
139
136
  xml.author(ref['author'])
@@ -45,9 +45,6 @@ module Commonmeta
45
45
  'state' => options[:state],
46
46
  'provider_id' => options[:provider_id],
47
47
  'client_id' => options[:client_id],
48
- 'depositor' => options[:depositor],
49
- 'email' => options[:email],
50
- 'registrant' => options[:registrant],
51
48
  'content_url' => options[:content_url]
52
49
  }
53
50
  string = File.read(options[:input])
@@ -62,9 +59,6 @@ module Commonmeta
62
59
  'state' => options[:state],
63
60
  'provider_id' => options[:provider_id],
64
61
  'client_id' => options[:client_id],
65
- 'depositor' => options[:depositor],
66
- 'email' => options[:email],
67
- 'registrant' => options[:registrant],
68
62
  'content_url' => options[:content_url],
69
63
  'creators' => options[:creators],
70
64
  'contributors' => options[:contributors],
@@ -94,11 +88,11 @@ module Commonmeta
94
88
  @client_id = hsh.to_h['client_id'].presence
95
89
  @content_url = hsh.to_h['content_url'].presence
96
90
 
97
- # options that come from the submission, needed
91
+ # options that come from the cli, needed
98
92
  # for crossref doi registration
99
- @depositor = hsh.to_h['depositor'].presence
100
- @email = hsh.to_h['email'].presence
101
- @registrant = hsh.to_h['registrant'].presence
93
+ @depositor = options[:depositor]
94
+ @email = options[:email]
95
+ @registrant = options[:registrant]
102
96
 
103
97
  # set attributes directly
104
98
  read_options = options.slice(
@@ -13,6 +13,7 @@ require_relative 'readers/codemeta_reader'
13
13
  require_relative 'readers/crossref_reader'
14
14
  require_relative 'readers/crossref_xml_reader'
15
15
  require_relative 'readers/datacite_reader'
16
+ require_relative 'readers/json_post_reader'
16
17
  require_relative 'readers/npm_reader'
17
18
  require_relative 'readers/ris_reader'
18
19
  require_relative 'readers/schema_org_reader'
@@ -46,6 +47,7 @@ module Commonmeta
46
47
  include Commonmeta::Readers::CrossrefXmlReader
47
48
  include Commonmeta::Readers::CslReader
48
49
  include Commonmeta::Readers::DataciteReader
50
+ include Commonmeta::Readers::JsonPostReader
49
51
  include Commonmeta::Readers::NpmReader
50
52
  include Commonmeta::Readers::RisReader
51
53
  include Commonmeta::Readers::SchemaOrgReader
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Commonmeta
4
+ module Readers
5
+ module JsonPostReader
6
+ def get_json_post(id: nil, **_options)
7
+ return { "string" => nil, "state" => "not_found" } unless id.present?
8
+
9
+ url = normalize_id(id)
10
+ response = HTTP.get(url)
11
+ return { "string" => nil, "state" => "not_found" } unless response.status.success?
12
+
13
+ { "string" => response.body.to_s }
14
+ end
15
+
16
+ def read_json_post(string: nil, **options)
17
+ read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
18
+ :sandbox, :validate, :ra))
19
+
20
+ meta = string.present? ? JSON.parse(string) : {}
21
+
22
+ id = options[:doi] ? normalize_doi(options[:doi]) : normalize_id(meta.fetch("id", nil))
23
+ url = normalize_url(meta.fetch("url", nil))
24
+ type = "Article"
25
+ creators = if meta.fetch("authors", nil).present?
26
+ get_authors(from_json_post(Array.wrap(meta.fetch("authors"))))
27
+ else
28
+ [{ "type" => "Organization", "name" => ":(unav)" }]
29
+ end
30
+ titles = [{ "title" => meta.fetch("title", nil) }]
31
+ publisher = { "name" => meta.dig("blog", "title") }
32
+
33
+ date = {}
34
+ date["published"] = get_iso8601_date(meta.dig("date_published")) if meta.dig("date_published").present?
35
+ date["updated"] = get_iso8601_date(meta.dig("date_modified")) if meta.dig("date_modified").present?
36
+
37
+ license = if meta.dig("blog", "license").present?
38
+ hsh_to_spdx("rightsURI" => meta.dig("blog", "license"))
39
+ end
40
+ home_page_url = normalize_url(meta.dig("blog", "home_page_url"))
41
+ container = if meta.dig("blog", "title").present?
42
+ { "type" => "Periodical",
43
+ "title" => meta.dig("blog", "title"),
44
+ "identifier" => home_page_url,
45
+ "identifierType" => "URL" }
46
+ end
47
+
48
+ descriptions = if meta.fetch("summary", nil).present?
49
+ [{ "description" => sanitize(meta.fetch("summary", nil)),
50
+ "descriptionType" => "Abstract" }]
51
+ else
52
+ []
53
+ end
54
+ language = meta.fetch("language", nil) || meta.fetch("blog", "language", nil)
55
+ state = id.present? || read_options.present? ? "findable" : "not_found"
56
+ subjects = Array.wrap(meta.fetch("tags", nil)).reduce([]) do |sum, subject|
57
+ sum += name_to_fos(subject)
58
+
59
+ sum
60
+ end
61
+
62
+ { "id" => id,
63
+ "type" => type,
64
+ "url" => url,
65
+ "titles" => titles,
66
+ "creators" => creators,
67
+ "publisher" => publisher,
68
+ "container" => container,
69
+ "date" => date,
70
+ "language" => language,
71
+ "descriptions" => descriptions,
72
+ "license" => license,
73
+ "subjects" => subjects.presence,
74
+ "state" => state }.compact.merge(read_options)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -468,6 +468,8 @@ module Commonmeta
468
468
  "cff"
469
469
  elsif %r{\A(http|https):/(/)?github\.com/(.+)\z}.match?(id)
470
470
  "cff"
471
+ elsif %r{\A(http|https):/(/)?rogue-scholar\.org/api/posts/(.+)\z}.match?(id)
472
+ "json_post"
471
473
  else
472
474
  "schema_org"
473
475
  end
@@ -875,6 +877,12 @@ module Commonmeta
875
877
  }
876
878
  end
877
879
 
880
+ def from_json_post(element)
881
+ mapping = { "url" => "id" }
882
+
883
+ map_hash_keys(element: element, mapping: mapping)
884
+ end
885
+
878
886
  def from_csl(element)
879
887
  Array.wrap(element).map do |a|
880
888
  if a["literal"].present?
@@ -1068,6 +1076,8 @@ module Commonmeta
1068
1076
 
1069
1077
  return iso8601_time.split(".").first + "Z" if iso8601_time.to_s.include? "."
1070
1078
 
1079
+ return iso8601_time.split("+").first + "Z" if iso8601_time.to_s.include? "+"
1080
+
1071
1081
  iso8601_time
1072
1082
  end
1073
1083
 
@@ -1084,6 +1094,15 @@ module Commonmeta
1084
1094
  dd.fetch("date", nil)
1085
1095
  end
1086
1096
 
1097
+ def get_link(links, link_type)
1098
+ ll = Array.wrap(links).find { |d| d["rel"] == link_type } || {}
1099
+ ll.fetch("href", nil)
1100
+ end
1101
+
1102
+ def rogue_scholar_api_url(id, _options = {})
1103
+ "https://rogue-scholar.org/api/posts/#{id}"
1104
+ end
1105
+
1087
1106
  # convert commonmeta dates to DataCite format
1088
1107
  def get_dates_from_date(date)
1089
1108
  return nil if date.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.0.9'
4
+ VERSION = '3.2.0'
5
5
  end
data/lib/commonmeta.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dotenv/load'
4
3
  require 'active_support/all'
5
4
  require 'nokogiri'
6
5
  ActiveSupport::XmlMini.backend = 'Nokogiri'
@@ -40,6 +40,16 @@ describe Commonmeta::Metadata, vcr: true do
40
40
  expect(subject.is_personal_name?(name: author['name'])).to be true
41
41
  end
42
42
 
43
+ it 'has unknown given name' do
44
+ author = { 'name' => 'Rintze Zelle' }
45
+ expect(subject.is_personal_name?(name: author['name'])).to be false
46
+ end
47
+
48
+ it 'has middle initial' do
49
+ author = { 'name' => 'Martin H. Fenner' }
50
+ expect(subject.is_personal_name?(name: author['name'])).to be true
51
+ end
52
+
43
53
  it 'has no info' do
44
54
  author = { 'name' => 'M Fenner' }
45
55
  expect(subject.is_personal_name?(name: author['name'])).to be false
data/spec/cli_spec.rb CHANGED
@@ -11,6 +11,7 @@ describe Commonmeta::CLI do
11
11
  describe "convert from id", vcr: true do
12
12
  SCHEMA_ORG_REGEX = /"@context": "http:\/\/schema.org"/
13
13
  CROSSREF_XML_REGEX = /<doi_batch/
14
+ DEPOSITOR_REGEX = /<depositor_name>test<\/depositor_name>/
14
15
  DATACITE_REGEX = /"types": {/
15
16
  BIBTEX_REGEX = /@article{https:\/\/doi.org\/10.7554\/elife.01567/
16
17
  BIBTEX_DATA_REGEX = /@misc{https:\/\/doi.org\/10.5061\/dryad.8515/
@@ -141,6 +142,12 @@ describe Commonmeta::CLI do
141
142
  expect { subject.convert id }.to output(DATACITE_REGEX).to_stdout
142
143
  end
143
144
 
145
+ it 'to crossref_xml' do
146
+ subject.options = { to: "crossref_xml", depositor: "test", email: "info@example.org", registrant: "test" }
147
+ expect { subject.convert id }.to output(CROSSREF_XML_REGEX).to_stdout
148
+ expect { subject.convert id }.to output(DEPOSITOR_REGEX).to_stdout
149
+ end
150
+
144
151
  # TODO
145
152
  # it 'to bibtex' do
146
153
  # subject.options = { to: "bibtex" }
@@ -166,6 +173,12 @@ describe Commonmeta::CLI do
166
173
  subject.options = { to: "datacite" }
167
174
  expect { subject.convert file }.to output(DATACITE_REGEX).to_stdout
168
175
  end
176
+
177
+ it 'to crossref_xml' do
178
+ subject.options = { to: "crossref_xml", depositor: "test", email: "info@example.org", registrant: "test" }
179
+ expect { subject.convert file }.to output(CROSSREF_XML_REGEX).to_stdout
180
+ expect { subject.convert file }.to output(DEPOSITOR_REGEX).to_stdout
181
+ end
169
182
  end
170
183
 
171
184
  context "crossref_xml", vcr: true do
@@ -209,8 +222,9 @@ describe Commonmeta::CLI do
209
222
  end
210
223
 
211
224
  it 'to crossref_xml' do
212
- subject.options = { to: "crossref_xml" }
225
+ subject.options = { to: "crossref_xml", depositor: "test", email: "info@example.org", registrant: "test" }
213
226
  expect { subject.convert file }.to output(CROSSREF_XML_REGEX).to_stdout
227
+ expect { subject.convert file }.to output(DEPOSITOR_REGEX).to_stdout
214
228
  end
215
229
 
216
230
  it 'to datacite' do
@@ -246,6 +260,12 @@ describe Commonmeta::CLI do
246
260
  expect { subject.convert file }.to output(/@article{https:\/\/doi.org\/10.5438\/4k3m-nyvg/).to_stdout
247
261
  end
248
262
 
263
+ it 'to crossref_xml' do
264
+ subject.options = { to: "crossref_xml", depositor: "test", email: "info@example.org", registrant: "test" }
265
+ expect { subject.convert file }.to output(CROSSREF_XML_REGEX).to_stdout
266
+ expect { subject.convert file }.to output(DEPOSITOR_REGEX).to_stdout
267
+ end
268
+
249
269
  it 'to datacite invalid' do
250
270
  file = fixture_path + "datacite_missing_creator.xml"
251
271
  subject.options = { to: "datacite", show_errors: "true" }