briard 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.github/workflows/rubocop.yml +50 -0
- data/.rubocop.yml +144 -620
- data/.rubocop_todo.yml +76 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +43 -6
- data/Rakefile +1 -1
- data/{bolognese.gemspec → briard.gemspec} +46 -38
- data/lib/briard/array.rb +2 -2
- data/lib/briard/author_utils.rb +79 -71
- data/lib/briard/cli.rb +12 -13
- data/lib/briard/crossref_utils.rb +73 -61
- data/lib/briard/datacite_utils.rb +132 -106
- data/lib/briard/doi_utils.rb +10 -10
- data/lib/briard/metadata.rb +96 -106
- data/lib/briard/metadata_utils.rb +87 -78
- data/lib/briard/readers/bibtex_reader.rb +65 -65
- data/lib/briard/readers/cff_reader.rb +88 -70
- data/lib/briard/readers/citeproc_reader.rb +90 -84
- data/lib/briard/readers/codemeta_reader.rb +68 -50
- data/lib/briard/readers/crosscite_reader.rb +2 -2
- data/lib/briard/readers/crossref_reader.rb +249 -210
- data/lib/briard/readers/datacite_json_reader.rb +3 -3
- data/lib/briard/readers/datacite_reader.rb +225 -189
- data/lib/briard/readers/npm_reader.rb +49 -42
- data/lib/briard/readers/ris_reader.rb +82 -80
- data/lib/briard/readers/schema_org_reader.rb +182 -159
- data/lib/briard/string.rb +1 -1
- data/lib/briard/utils.rb +4 -4
- data/lib/briard/version.rb +3 -1
- data/lib/briard/whitelist_scrubber.rb +11 -4
- data/lib/briard/writers/bibtex_writer.rb +14 -8
- data/lib/briard/writers/cff_writer.rb +33 -26
- data/lib/briard/writers/codemeta_writer.rb +19 -15
- data/lib/briard/writers/csv_writer.rb +6 -4
- data/lib/briard/writers/datacite_json_writer.rb +8 -2
- data/lib/briard/writers/jats_writer.rb +33 -28
- data/lib/briard/writers/rdf_xml_writer.rb +1 -1
- data/lib/briard/writers/ris_writer.rb +30 -18
- data/lib/briard/writers/turtle_writer.rb +1 -1
- data/lib/briard.rb +6 -6
- data/rubocop.sarif +0 -0
- data/spec/array_spec.rb +5 -5
- data/spec/author_utils_spec.rb +151 -132
- data/spec/datacite_utils_spec.rb +135 -83
- data/spec/doi_utils_spec.rb +168 -164
- data/spec/find_from_format_spec.rb +69 -69
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/onlies_keep_specific_tags.yml +65 -0
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/removes_a_tags.yml +65 -0
- data/spec/metadata_spec.rb +91 -90
- data/spec/readers/bibtex_reader_spec.rb +43 -38
- data/spec/readers/cff_reader_spec.rb +165 -153
- data/spec/readers/citeproc_reader_spec.rb +45 -40
- data/spec/readers/codemeta_reader_spec.rb +128 -115
- data/spec/readers/crosscite_reader_spec.rb +34 -24
- data/spec/readers/crossref_reader_spec.rb +1098 -939
- data/spec/readers/datacite_json_reader_spec.rb +53 -40
- data/spec/readers/datacite_reader_spec.rb +1541 -1337
- data/spec/readers/npm_reader_spec.rb +48 -43
- data/spec/readers/ris_reader_spec.rb +53 -47
- data/spec/readers/schema_org_reader_spec.rb +329 -267
- data/spec/spec_helper.rb +6 -5
- data/spec/utils_spec.rb +371 -347
- data/spec/writers/bibtex_writer_spec.rb +143 -143
- data/spec/writers/cff_writer_spec.rb +96 -90
- data/spec/writers/citation_writer_spec.rb +34 -33
- data/spec/writers/citeproc_writer_spec.rb +226 -224
- data/spec/writers/codemeta_writer_spec.rb +18 -16
- data/spec/writers/crosscite_writer_spec.rb +91 -73
- data/spec/writers/crossref_writer_spec.rb +99 -91
- data/spec/writers/csv_writer_spec.rb +70 -70
- data/spec/writers/datacite_json_writer_spec.rb +78 -68
- data/spec/writers/datacite_writer_spec.rb +417 -322
- data/spec/writers/jats_writer_spec.rb +177 -161
- data/spec/writers/rdf_xml_writer_spec.rb +68 -63
- data/spec/writers/ris_writer_spec.rb +162 -162
- data/spec/writers/turtle_writer_spec.rb +47 -47
- metadata +250 -160
- data/.github/workflows/release.yml +0 -47
data/spec/utils_spec.rb
CHANGED
@@ -3,652 +3,676 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Briard::Metadata, vcr: true do
|
6
|
-
|
6
|
+
subject { described_class.new(input: input, from: 'crossref') }
|
7
7
|
|
8
|
-
|
8
|
+
let(:input) { 'https://doi.org/10.1101/097196' }
|
9
9
|
|
10
|
-
context
|
11
|
-
it
|
12
|
-
str =
|
10
|
+
context 'validate url' do
|
11
|
+
it 'DOI' do
|
12
|
+
str = 'https://doi.org/10.5438/0000-00ss'
|
13
13
|
response = subject.validate_url(str)
|
14
|
-
expect(response).to eq(
|
14
|
+
expect(response).to eq('DOI')
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
str =
|
17
|
+
it 'URL' do
|
18
|
+
str = 'https://blog.datacite.org/eating-your-own-dog-food'
|
19
19
|
response = subject.validate_url(str)
|
20
|
-
expect(response).to eq(
|
20
|
+
expect(response).to eq('URL')
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
str =
|
23
|
+
it 'ISSN' do
|
24
|
+
str = 'ISSN 2050-084X'
|
25
25
|
response = subject.validate_url(str)
|
26
|
-
expect(response).to eq(
|
26
|
+
expect(response).to eq('ISSN')
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
str =
|
29
|
+
it 'string' do
|
30
|
+
str = 'eating-your-own-dog-food'
|
31
31
|
response = subject.validate_url(str)
|
32
|
-
expect(response).to
|
32
|
+
expect(response.nil?).to be(true)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
37
|
-
it
|
38
|
-
orcid =
|
36
|
+
context 'validate_orcid' do
|
37
|
+
it 'validate_orcid' do
|
38
|
+
orcid = 'http://orcid.org/0000-0002-2590-225X'
|
39
39
|
response = subject.validate_orcid(orcid)
|
40
|
-
expect(response).to eq(
|
40
|
+
expect(response).to eq('0000-0002-2590-225X')
|
41
41
|
end
|
42
42
|
|
43
|
-
it
|
44
|
-
orcid =
|
43
|
+
it 'validate_orcid https' do
|
44
|
+
orcid = 'https://orcid.org/0000-0002-2590-225X'
|
45
45
|
response = subject.validate_orcid(orcid)
|
46
|
-
expect(response).to eq(
|
46
|
+
expect(response).to eq('0000-0002-2590-225X')
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
50
|
-
orcid =
|
49
|
+
it 'validate_orcid id' do
|
50
|
+
orcid = '0000-0002-2590-225X'
|
51
51
|
response = subject.validate_orcid(orcid)
|
52
|
-
expect(response).to eq(
|
52
|
+
expect(response).to eq('0000-0002-2590-225X')
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
56
|
-
orcid =
|
55
|
+
it 'validate_orcid www' do
|
56
|
+
orcid = 'http://www.orcid.org/0000-0002-2590-225X'
|
57
57
|
response = subject.validate_orcid(orcid)
|
58
|
-
expect(response).to eq(
|
58
|
+
expect(response).to eq('0000-0002-2590-225X')
|
59
59
|
end
|
60
60
|
|
61
|
-
it
|
62
|
-
orcid =
|
61
|
+
it 'validate_orcid with spaces' do
|
62
|
+
orcid = '0000 0002 1394 3097'
|
63
63
|
response = subject.validate_orcid(orcid)
|
64
|
-
expect(response).to eq(
|
64
|
+
expect(response).to eq('0000-0002-1394-3097')
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
orcid =
|
67
|
+
it 'validate_orcid sandbox' do
|
68
|
+
orcid = 'http://sandbox.orcid.org/0000-0002-2590-225X'
|
69
69
|
response = subject.validate_orcid(orcid)
|
70
|
-
expect(response).to eq(
|
70
|
+
expect(response).to eq('0000-0002-2590-225X')
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
orcid =
|
73
|
+
it 'validate_orcid sandbox https' do
|
74
|
+
orcid = 'https://sandbox.orcid.org/0000-0002-2590-225X'
|
75
75
|
response = subject.validate_orcid(orcid)
|
76
|
-
expect(response).to eq(
|
76
|
+
expect(response).to eq('0000-0002-2590-225X')
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
80
|
-
orcid =
|
79
|
+
it 'validate_orcid wrong id' do
|
80
|
+
orcid = '0000-0002-1394-309'
|
81
81
|
response = subject.validate_orcid(orcid)
|
82
|
-
expect(response).to
|
82
|
+
expect(response.nil?).to be(true)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
context
|
87
|
-
it
|
88
|
-
orcid =
|
86
|
+
context 'validate_orcid_scheme' do
|
87
|
+
it 'validate_orcid_scheme' do
|
88
|
+
orcid = 'http://orcid.org'
|
89
89
|
response = subject.validate_orcid_scheme(orcid)
|
90
|
-
expect(response).to eq(
|
90
|
+
expect(response).to eq('orcid.org')
|
91
91
|
end
|
92
92
|
|
93
|
-
it
|
94
|
-
orcid =
|
93
|
+
it 'validate_orcid_scheme trailing slash' do
|
94
|
+
orcid = 'http://orcid.org/'
|
95
95
|
response = subject.validate_orcid_scheme(orcid)
|
96
|
-
expect(response).to eq(
|
96
|
+
expect(response).to eq('orcid.org')
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
100
|
-
orcid =
|
99
|
+
it 'validate_orcid_scheme https' do
|
100
|
+
orcid = 'https://orcid.org'
|
101
101
|
response = subject.validate_orcid_scheme(orcid)
|
102
|
-
expect(response).to eq(
|
102
|
+
expect(response).to eq('orcid.org')
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
orcid =
|
105
|
+
it 'validate_orcid_scheme www' do
|
106
|
+
orcid = 'http://www.orcid.org'
|
107
107
|
response = subject.validate_orcid_scheme(orcid)
|
108
|
-
expect(response).to eq(
|
108
|
+
expect(response).to eq('orcid.org')
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
context
|
113
|
-
it
|
114
|
-
element =
|
112
|
+
context 'parse attributes' do
|
113
|
+
it 'string' do
|
114
|
+
element = '10.5061/DRYAD.8515'
|
115
115
|
response = subject.parse_attributes(element)
|
116
|
-
expect(response).to eq(
|
116
|
+
expect(response).to eq('10.5061/DRYAD.8515')
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
120
|
-
element = {
|
119
|
+
it 'hash' do
|
120
|
+
element = { '__content__' => '10.5061/DRYAD.8515' }
|
121
121
|
response = subject.parse_attributes(element)
|
122
|
-
expect(response).to eq(
|
122
|
+
expect(response).to eq('10.5061/DRYAD.8515')
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
126
|
-
element = [{
|
125
|
+
it 'array' do
|
126
|
+
element = [{ '__content__' => '10.5061/DRYAD.8515' }]
|
127
127
|
response = subject.parse_attributes(element)
|
128
|
-
expect(response).to eq(
|
128
|
+
expect(response).to eq('10.5061/DRYAD.8515')
|
129
129
|
end
|
130
130
|
|
131
|
-
it
|
132
|
-
element = [
|
131
|
+
it 'array of strings' do
|
132
|
+
element = %w[datacite doi metadata featured]
|
133
133
|
response = subject.parse_attributes(element)
|
134
|
-
expect(response).to eq([
|
134
|
+
expect(response).to eq(%w[datacite doi metadata featured])
|
135
135
|
end
|
136
136
|
|
137
|
-
it
|
137
|
+
it 'nil' do
|
138
138
|
element = nil
|
139
139
|
response = subject.parse_attributes(element)
|
140
|
-
expect(response).to
|
140
|
+
expect(response.nil?).to be(true)
|
141
141
|
end
|
142
142
|
|
143
|
-
it
|
144
|
-
element = [{
|
143
|
+
it 'first' do
|
144
|
+
element = [{ '__content__' => '10.5061/DRYAD.8515/1' },
|
145
|
+
{ '__content__' => '10.5061/DRYAD.8515/2' }]
|
145
146
|
response = subject.parse_attributes(element, first: true)
|
146
|
-
expect(response).to eq(
|
147
|
+
expect(response).to eq('10.5061/DRYAD.8515/1')
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
context
|
151
|
-
it
|
152
|
-
doi =
|
151
|
+
context 'normalize id' do
|
152
|
+
it 'doi' do
|
153
|
+
doi = '10.5061/DRYAD.8515'
|
153
154
|
response = subject.normalize_id(doi)
|
154
|
-
expect(response).to eq(
|
155
|
+
expect(response).to eq('https://doi.org/10.5061/dryad.8515')
|
155
156
|
end
|
156
157
|
|
157
|
-
it
|
158
|
-
doi =
|
158
|
+
it 'doi as url' do
|
159
|
+
doi = 'http://dx.doi.org/10.5061/DRYAD.8515'
|
159
160
|
response = subject.normalize_id(doi)
|
160
|
-
expect(response).to eq(
|
161
|
+
expect(response).to eq('https://doi.org/10.5061/dryad.8515')
|
161
162
|
end
|
162
163
|
|
163
|
-
it
|
164
|
-
url =
|
164
|
+
it 'url' do
|
165
|
+
url = 'https://blog.datacite.org/eating-your-own-dog-food/'
|
165
166
|
response = subject.normalize_id(url)
|
166
|
-
expect(response).to eq(
|
167
|
+
expect(response).to eq('https://blog.datacite.org/eating-your-own-dog-food')
|
167
168
|
end
|
168
169
|
|
169
|
-
it
|
170
|
-
url =
|
170
|
+
it 'url with utf-8' do
|
171
|
+
url = 'http://www.詹姆斯.com/eating-your-own-dog-food/'
|
171
172
|
response = subject.normalize_id(url)
|
172
|
-
expect(response).to eq(
|
173
|
+
expect(response).to eq('http://www.xn--8ws00zhy3a.com/eating-your-own-dog-food')
|
173
174
|
end
|
174
175
|
|
175
|
-
it
|
176
|
-
url =
|
176
|
+
it 'ftp' do
|
177
|
+
url = 'ftp://blog.datacite.org/eating-your-own-dog-food/'
|
177
178
|
response = subject.normalize_id(url)
|
178
|
-
expect(response).to
|
179
|
+
expect(response.nil?).to be(true)
|
179
180
|
end
|
180
181
|
|
181
|
-
it
|
182
|
-
url =
|
182
|
+
it 'invalid url' do
|
183
|
+
url = 'http://'
|
183
184
|
response = subject.normalize_id(url)
|
184
|
-
expect(response).to
|
185
|
+
expect(response.nil?).to be(true)
|
185
186
|
end
|
186
187
|
|
187
|
-
it
|
188
|
-
url =
|
188
|
+
it 'string' do
|
189
|
+
url = 'eating-your-own-dog-food'
|
189
190
|
response = subject.normalize_id(url)
|
190
|
-
expect(response).to
|
191
|
+
expect(response.nil?).to be(true)
|
191
192
|
end
|
192
193
|
|
193
|
-
it
|
194
|
-
url =
|
194
|
+
it 'sandbox via url' do
|
195
|
+
url = 'https://handle.stage.datacite.org/10.20375/0000-0001-ddb8-7'
|
195
196
|
response = subject.normalize_id(url)
|
196
|
-
expect(response).to eq(
|
197
|
+
expect(response).to eq('https://handle.stage.datacite.org/10.20375/0000-0001-ddb8-7')
|
197
198
|
end
|
198
199
|
|
199
|
-
it
|
200
|
-
url =
|
200
|
+
it 'sandbox via options' do
|
201
|
+
url = '10.20375/0000-0001-ddb8-7'
|
201
202
|
response = subject.normalize_id(url, sandbox: true)
|
202
|
-
expect(response).to eq(
|
203
|
+
expect(response).to eq('https://handle.stage.datacite.org/10.20375/0000-0001-ddb8-7')
|
203
204
|
end
|
204
205
|
end
|
205
206
|
|
206
|
-
context
|
207
|
-
it
|
208
|
-
ids = [{
|
207
|
+
context 'normalize ids' do
|
208
|
+
it 'doi' do
|
209
|
+
ids = [{ '@type' => 'CreativeWork', '@id' => 'https://doi.org/10.5438/0012' },
|
210
|
+
{ '@type' => 'CreativeWork', '@id' => 'https://doi.org/10.5438/55E5-T5C0' }]
|
209
211
|
response = subject.normalize_ids(ids: ids)
|
210
|
-
expect(response).to eq([{
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
212
|
+
expect(response).to eq([{ 'relatedIdentifier' => '10.5438/0012',
|
213
|
+
'relatedIdentifierType' => 'DOI',
|
214
|
+
'resourceTypeGeneral' => 'Text' },
|
215
|
+
{ 'relatedIdentifier' => '10.5438/55e5-t5c0',
|
216
|
+
'relatedIdentifierType' => 'DOI',
|
217
|
+
'resourceTypeGeneral' => 'Text' }])
|
216
218
|
end
|
217
219
|
|
218
|
-
it
|
219
|
-
ids = [{
|
220
|
+
it 'url' do
|
221
|
+
ids = [{ '@type' => 'CreativeWork',
|
222
|
+
'@id' => 'https://blog.datacite.org/eating-your-own-dog-food/' }]
|
220
223
|
response = subject.normalize_ids(ids: ids)
|
221
|
-
expect(response).to eq(
|
224
|
+
expect(response).to eq(
|
225
|
+
'relatedIdentifier' => 'https://blog.datacite.org/eating-your-own-dog-food', 'relatedIdentifierType' => 'URL', 'resourceTypeGeneral' => 'Text'
|
226
|
+
)
|
222
227
|
end
|
223
228
|
end
|
224
229
|
|
225
|
-
context
|
226
|
-
it
|
227
|
-
url =
|
230
|
+
context 'normalize url' do
|
231
|
+
it 'with trailing slash' do
|
232
|
+
url = 'http://creativecommons.org/publicdomain/zero/1.0/'
|
228
233
|
response = subject.normalize_url(url)
|
229
|
-
expect(response).to eq(
|
234
|
+
expect(response).to eq('http://creativecommons.org/publicdomain/zero/1.0')
|
230
235
|
end
|
231
236
|
|
232
|
-
it
|
233
|
-
url =
|
237
|
+
it 'with trailing slash and to https' do
|
238
|
+
url = 'http://creativecommons.org/publicdomain/zero/1.0/'
|
234
239
|
response = subject.normalize_url(url, https: true)
|
235
|
-
expect(response).to eq(
|
240
|
+
expect(response).to eq('https://creativecommons.org/publicdomain/zero/1.0')
|
236
241
|
end
|
237
242
|
|
238
|
-
it
|
239
|
-
url =
|
243
|
+
it 'uri' do
|
244
|
+
url = 'info:eu-repo/semantics/openAccess'
|
240
245
|
response = subject.normalize_url(url)
|
241
|
-
expect(response).to eq(
|
246
|
+
expect(response).to eq('info:eu-repo/semantics/openAccess')
|
242
247
|
end
|
243
248
|
end
|
244
249
|
|
245
|
-
context
|
246
|
-
it
|
247
|
-
url =
|
250
|
+
context 'normalize cc url' do
|
251
|
+
it 'with trailing slash' do
|
252
|
+
url = 'http://creativecommons.org/publicdomain/zero/1.0/'
|
248
253
|
response = subject.normalize_cc_url(url)
|
249
|
-
expect(response).to eq(
|
254
|
+
expect(response).to eq('https://creativecommons.org/publicdomain/zero/1.0/legalcode')
|
250
255
|
end
|
251
256
|
|
252
|
-
it
|
253
|
-
url =
|
257
|
+
it 'with trailing slash and to https' do
|
258
|
+
url = 'http://creativecommons.org/publicdomain/zero/1.0/'
|
254
259
|
response = subject.normalize_cc_url(url)
|
255
|
-
expect(response).to eq(
|
260
|
+
expect(response).to eq('https://creativecommons.org/publicdomain/zero/1.0/legalcode')
|
256
261
|
end
|
257
262
|
|
258
|
-
it
|
259
|
-
url =
|
263
|
+
it 'not found' do
|
264
|
+
url = 'http://creativecommons.org/publicdomain/zero/2.0/'
|
260
265
|
response = subject.normalize_cc_url(url)
|
261
|
-
expect(response).to eq(
|
266
|
+
expect(response).to eq('https://creativecommons.org/publicdomain/zero/2.0')
|
262
267
|
end
|
263
268
|
end
|
264
269
|
|
265
|
-
context
|
266
|
-
it
|
267
|
-
input = [{
|
270
|
+
context 'normalize issn' do
|
271
|
+
it 'from array' do
|
272
|
+
input = [{ 'media_type' => 'print', '__content__' => '13040855' },
|
273
|
+
{ 'media_type' => 'electronic', '__content__' => '21468427' }]
|
268
274
|
response = subject.normalize_issn(input)
|
269
|
-
expect(response).to eq(
|
275
|
+
expect(response).to eq('2146-8427')
|
270
276
|
end
|
271
277
|
|
272
|
-
it
|
278
|
+
it 'from empty array' do
|
273
279
|
input = []
|
274
280
|
response = subject.normalize_issn(input)
|
275
|
-
expect(response).to
|
281
|
+
expect(response.nil?).to be(true)
|
276
282
|
end
|
277
283
|
|
278
|
-
it
|
279
|
-
input = {
|
284
|
+
it 'from hash' do
|
285
|
+
input = { 'media_type' => 'electronic', '__content__' => '21468427' }
|
280
286
|
response = subject.normalize_issn(input)
|
281
|
-
expect(response).to eq(
|
287
|
+
expect(response).to eq('2146-8427')
|
282
288
|
end
|
283
289
|
|
284
|
-
it
|
285
|
-
input =
|
290
|
+
it 'from string' do
|
291
|
+
input = '2146-8427'
|
286
292
|
response = subject.normalize_issn(input)
|
287
|
-
expect(response).to eq(
|
293
|
+
expect(response).to eq('2146-8427')
|
288
294
|
end
|
289
295
|
end
|
290
296
|
|
291
|
-
context
|
292
|
-
it
|
293
|
-
author = {
|
297
|
+
context 'to_schema_org' do
|
298
|
+
it 'with id' do
|
299
|
+
author = { 'type' => 'Person', 'id' => 'http://orcid.org/0000-0003-1419-2405', 'givenName' => 'Martin', 'familyName' => 'Fenner', 'name' => 'Martin Fenner' }
|
294
300
|
response = subject.to_schema_org(author)
|
295
|
-
expect(response).to eq(
|
301
|
+
expect(response).to eq('givenName' => 'Martin', 'familyName' => 'Fenner',
|
302
|
+
'name' => 'Martin Fenner', '@type' => 'Person', '@id' => 'http://orcid.org/0000-0003-1419-2405')
|
296
303
|
end
|
297
304
|
end
|
298
305
|
|
299
|
-
context
|
300
|
-
it
|
301
|
-
author = {
|
306
|
+
context 'from_schema_org' do
|
307
|
+
it 'with @id' do
|
308
|
+
author = { '@type' => 'Person', '@id' => 'http://orcid.org/0000-0003-1419-2405', 'givenName' => 'Martin', 'familyName' => 'Fenner', 'name' => 'Martin Fenner' }
|
302
309
|
response = subject.from_schema_org(author)
|
303
|
-
expect(response).to eq(
|
310
|
+
expect(response).to eq('givenName' => 'Martin', 'familyName' => 'Fenner',
|
311
|
+
'name' => 'Martin Fenner', 'type' => 'Person', 'id' => 'http://orcid.org/0000-0003-1419-2405')
|
304
312
|
end
|
305
313
|
end
|
306
314
|
|
307
|
-
context
|
308
|
-
it
|
309
|
-
authors = [{
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
}}]
|
315
|
+
context 'from_schema_org_creators' do
|
316
|
+
it 'with affiliation' do
|
317
|
+
authors = [{ '@type' => 'Person', '@id' => 'http://orcid.org/0000-0003-1419-2405', 'givenName' => 'Martin', 'familyName' => 'Fenner', 'name' => 'Martin Fenner', 'affiliation' => {
|
318
|
+
'@id' => 'https://ror.org/04wxnsj81',
|
319
|
+
'name' => 'DataCite',
|
320
|
+
'@type' => 'Organization'
|
321
|
+
} }]
|
314
322
|
response = subject.from_schema_org_creators(authors)
|
315
|
-
expect(response).to eq([{
|
316
|
-
{
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
323
|
+
expect(response).to eq([{ 'affiliation' =>
|
324
|
+
{ 'affiliationIdentifier' => 'https://ror.org/04wxnsj81',
|
325
|
+
'affiliationIdentifierScheme' => 'ROR',
|
326
|
+
'__content__' => 'DataCite',
|
327
|
+
'schemeUri' => 'https://ror.org/' },
|
328
|
+
'creatorName' => { '__content__' => 'Martin Fenner',
|
329
|
+
'nameType' => 'Personal' },
|
330
|
+
'familyName' => 'Fenner',
|
331
|
+
'givenName' => 'Martin',
|
332
|
+
'nameIdentifier' =>
|
333
|
+
[{ '__content__' => 'http://orcid.org/0000-0003-1419-2405',
|
334
|
+
'nameIdentifierScheme' => 'ORCID',
|
335
|
+
'schemeUri' => 'https://orcid.org' }] }])
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'without affiliation' do
|
339
|
+
authors = [{ '@type' => 'Person', '@id' => 'http://orcid.org/0000-0003-1419-2405',
|
340
|
+
'givenName' => 'Martin', 'familyName' => 'Fenner', 'name' => 'Martin Fenner' }]
|
331
341
|
response = subject.from_schema_org_creators(authors)
|
332
|
-
expect(response).to eq([{
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
[{
|
337
|
-
|
338
|
-
|
342
|
+
expect(response).to eq([{ 'creatorName' => { '__content__' => 'Martin Fenner', 'nameType' => 'Personal' },
|
343
|
+
'familyName' => 'Fenner',
|
344
|
+
'givenName' => 'Martin',
|
345
|
+
'nameIdentifier' =>
|
346
|
+
[{ '__content__' => 'http://orcid.org/0000-0003-1419-2405',
|
347
|
+
'nameIdentifierScheme' => 'ORCID',
|
348
|
+
'schemeUri' => 'https://orcid.org' }] }])
|
339
349
|
end
|
340
350
|
end
|
341
351
|
|
342
|
-
context
|
343
|
-
it
|
344
|
-
identifiers = [
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
352
|
+
context 'to_schema_org_identifiers' do
|
353
|
+
it 'with identifiers' do
|
354
|
+
identifiers = [
|
355
|
+
{ 'identifier' => 'https://doi.org/10.23725/8na3-9s47',
|
356
|
+
'identifierType' => 'DOI' }, { 'identifierType' => 'md5', 'identifier' => '3b33f6b9338fccab0901b7d317577ea3' }, { 'identifierType' => 'minid', 'identifier' => 'ark:/99999/fk41CrU4eszeLUDe' }, { 'identifierType' => 'dataguid', 'identifier' => 'dg.4503/c3d66dc9-58da-411c-83c4-dd656aa3c4b7' }
|
357
|
+
]
|
358
|
+
response = subject.to_schema_org_identifiers(identifiers, type: 'Dataset')
|
359
|
+
expect(response).to eq([{ '@type' => 'PropertyValue', 'propertyID' => 'DOI', 'value' => 'https://doi.org/10.23725/8na3-9s47' },
|
360
|
+
{ '@type' => 'PropertyValue',
|
361
|
+
'propertyID' => 'md5',
|
362
|
+
'value' => '3b33f6b9338fccab0901b7d317577ea3' },
|
363
|
+
{ '@type' => 'PropertyValue',
|
364
|
+
'propertyID' => 'minid',
|
365
|
+
'value' => 'ark:/99999/fk41CrU4eszeLUDe' },
|
366
|
+
{ '@type' => 'PropertyValue',
|
367
|
+
'propertyID' => 'dataguid',
|
368
|
+
'value' => 'dg.4503/c3d66dc9-58da-411c-83c4-dd656aa3c4b7' }])
|
356
369
|
end
|
357
370
|
end
|
358
371
|
|
359
|
-
context
|
360
|
-
it '
|
361
|
-
text =
|
372
|
+
context 'sanitize' do
|
373
|
+
it 'removes a tags' do
|
374
|
+
text = 'In 1998 <strong>Tim Berners-Lee</strong> coined the term <a href="https://www.w3.org/Provider/Style/URI">cool URIs</a>'
|
362
375
|
content = subject.sanitize(text)
|
363
|
-
expect(content).to eq(
|
376
|
+
expect(content).to eq('In 1998 <strong>Tim Berners-Lee</strong> coined the term cool URIs')
|
364
377
|
end
|
365
378
|
|
366
|
-
it '
|
367
|
-
text =
|
368
|
-
content = subject.sanitize(text, tags: [
|
369
|
-
expect(content).to eq(
|
379
|
+
it 'onlies keep specific tags' do
|
380
|
+
text = 'In 1998 <strong>Tim Berners-Lee</strong> coined the term <a href="https://www.w3.org/Provider/Style/URI">cool URIs</a>'
|
381
|
+
content = subject.sanitize(text, tags: ['a'])
|
382
|
+
expect(content).to eq('In 1998 Tim Berners-Lee coined the term <a href="https://www.w3.org/Provider/Style/URI">cool URIs</a>')
|
370
383
|
end
|
371
384
|
end
|
372
385
|
|
373
|
-
context
|
374
|
-
it
|
375
|
-
time =
|
386
|
+
context 'get_datetime_from_time' do
|
387
|
+
it 'present' do
|
388
|
+
time = '20200226071709'
|
376
389
|
response = subject.get_datetime_from_time(time)
|
377
|
-
expect(response).to eq(
|
390
|
+
expect(response).to eq('2020-02-26T07:17:09Z')
|
378
391
|
end
|
379
392
|
|
380
|
-
it
|
381
|
-
time =
|
393
|
+
it 'past' do
|
394
|
+
time = '18770312071709'
|
382
395
|
response = subject.get_datetime_from_time(time)
|
383
|
-
expect(response).to eq(
|
396
|
+
expect(response).to eq('1877-03-12T07:17:09Z')
|
384
397
|
end
|
385
398
|
|
386
|
-
it
|
387
|
-
time =
|
399
|
+
it 'future' do
|
400
|
+
time = '20970114071709'
|
388
401
|
response = subject.get_datetime_from_time(time)
|
389
|
-
expect(response).to eq(
|
402
|
+
expect(response).to eq('2097-01-14T07:17:09Z')
|
390
403
|
end
|
391
404
|
|
392
|
-
it
|
393
|
-
time =
|
405
|
+
it 'invalid' do
|
406
|
+
time = '20201587168864794'
|
394
407
|
response = subject.get_datetime_from_time(time)
|
395
|
-
expect(response).to
|
408
|
+
expect(response.nil?).to be(true)
|
396
409
|
end
|
397
410
|
|
398
|
-
it
|
411
|
+
it 'nil' do
|
399
412
|
time = nil
|
400
413
|
response = subject.get_datetime_from_time(time)
|
401
|
-
expect(response).to
|
414
|
+
expect(response.nil?).to be(true)
|
402
415
|
end
|
403
416
|
end
|
404
417
|
|
405
|
-
context
|
406
|
-
it
|
407
|
-
date =
|
418
|
+
context 'get_date_parts' do
|
419
|
+
it 'date' do
|
420
|
+
date = '2016-12-20'
|
408
421
|
response = subject.get_date_parts(date)
|
409
|
-
expect(response).to eq(
|
422
|
+
expect(response).to eq('date-parts' => [[2016, 12, 20]])
|
410
423
|
end
|
411
424
|
|
412
|
-
it
|
413
|
-
date =
|
425
|
+
it 'year-month' do
|
426
|
+
date = '2016-12'
|
414
427
|
response = subject.get_date_parts(date)
|
415
|
-
expect(response).to eq(
|
428
|
+
expect(response).to eq('date-parts' => [[2016, 12]])
|
416
429
|
end
|
417
430
|
|
418
|
-
it
|
419
|
-
date =
|
431
|
+
it 'year' do
|
432
|
+
date = '2016'
|
420
433
|
response = subject.get_date_parts(date)
|
421
|
-
expect(response).to eq(
|
434
|
+
expect(response).to eq('date-parts' => [[2016]])
|
422
435
|
end
|
423
436
|
end
|
424
437
|
|
425
|
-
context
|
426
|
-
it
|
438
|
+
context 'get_date_from_parts' do
|
439
|
+
it 'date' do
|
427
440
|
response = subject.get_date_from_parts(2016, 12, 20)
|
428
|
-
expect(response).to eq(
|
441
|
+
expect(response).to eq('2016-12-20')
|
429
442
|
end
|
430
443
|
|
431
|
-
it
|
444
|
+
it 'year-month' do
|
432
445
|
response = subject.get_date_from_parts(2016, 12)
|
433
|
-
expect(response).to eq(
|
446
|
+
expect(response).to eq('2016-12')
|
434
447
|
end
|
435
448
|
|
436
|
-
it
|
449
|
+
it 'year' do
|
437
450
|
response = subject.get_date_from_parts(2016)
|
438
|
-
expect(response).to eq(
|
451
|
+
expect(response).to eq('2016')
|
439
452
|
end
|
440
453
|
end
|
441
454
|
|
442
|
-
context
|
443
|
-
it
|
444
|
-
date_as_parts = {
|
455
|
+
context 'get_date_from_date_parts' do
|
456
|
+
it 'date' do
|
457
|
+
date_as_parts = { 'date-parts' => [[2016, 12, 20]] }
|
445
458
|
response = subject.get_date_from_date_parts(date_as_parts)
|
446
|
-
expect(response).to eq(
|
459
|
+
expect(response).to eq('2016-12-20')
|
447
460
|
end
|
448
461
|
|
449
|
-
it
|
450
|
-
date_as_parts = {
|
462
|
+
it 'year-month' do
|
463
|
+
date_as_parts = { 'date-parts' => [[2016, 12]] }
|
451
464
|
response = subject.get_date_from_date_parts(date_as_parts)
|
452
|
-
expect(response).to eq(
|
465
|
+
expect(response).to eq('2016-12')
|
453
466
|
end
|
454
467
|
|
455
|
-
it
|
456
|
-
date_as_parts = {
|
468
|
+
it 'year' do
|
469
|
+
date_as_parts = { 'date-parts' => [[2016]] }
|
457
470
|
response = subject.get_date_from_date_parts(date_as_parts)
|
458
|
-
expect(response).to eq(
|
471
|
+
expect(response).to eq('2016')
|
459
472
|
end
|
460
473
|
end
|
461
474
|
|
462
|
-
context
|
463
|
-
it
|
464
|
-
dates = [{
|
465
|
-
response = subject.get_date(dates,
|
466
|
-
expect(response).to eq(
|
475
|
+
context 'get_date' do
|
476
|
+
it 'publication date' do
|
477
|
+
dates = [{ 'date' => '2016-12-20', 'dateType' => 'Issued' }]
|
478
|
+
response = subject.get_date(dates, 'Issued')
|
479
|
+
expect(response).to eq('2016-12-20')
|
467
480
|
end
|
468
481
|
end
|
469
482
|
|
470
|
-
context
|
471
|
-
it
|
483
|
+
context 'get_series_information' do
|
484
|
+
it 'only title' do
|
472
485
|
str = nil
|
473
486
|
response = subject.get_series_information(str)
|
474
487
|
expect(response).to eq({})
|
475
488
|
end
|
476
489
|
|
477
|
-
it
|
478
|
-
str =
|
490
|
+
it 'only title' do
|
491
|
+
str = 'DataCite Blog'
|
479
492
|
response = subject.get_series_information(str)
|
480
|
-
expect(response).to eq(
|
493
|
+
expect(response).to eq('title' => 'DataCite Blog')
|
481
494
|
end
|
482
495
|
|
483
|
-
it
|
484
|
-
str =
|
496
|
+
it 'title and pages' do
|
497
|
+
str = 'DataCite Blog, 1-3'
|
485
498
|
response = subject.get_series_information(str)
|
486
|
-
expect(response).to eq(
|
499
|
+
expect(response).to eq('firstPage' => '1', 'lastPage' => '3', 'title' => 'DataCite Blog')
|
487
500
|
end
|
488
501
|
|
489
|
-
it
|
490
|
-
str =
|
502
|
+
it 'title, volume and pages' do
|
503
|
+
str = 'DataCite Blog, 7, 1-3'
|
491
504
|
response = subject.get_series_information(str)
|
492
|
-
expect(response).to eq(
|
505
|
+
expect(response).to eq('firstPage' => '1', 'lastPage' => '3', 'title' => 'DataCite Blog',
|
506
|
+
'volume' => '7')
|
493
507
|
end
|
494
508
|
|
495
|
-
it
|
496
|
-
str =
|
509
|
+
it 'title, volume, issue and pages' do
|
510
|
+
str = 'DataCite Blog, 7(11), 1-3'
|
497
511
|
response = subject.get_series_information(str)
|
498
|
-
expect(response).to eq(
|
512
|
+
expect(response).to eq('firstPage' => '1', 'issue' => '11', 'lastPage' => '3',
|
513
|
+
'title' => 'DataCite Blog', 'volume' => '7')
|
499
514
|
end
|
500
515
|
end
|
501
516
|
|
502
|
-
context
|
503
|
-
it
|
504
|
-
url =
|
517
|
+
context 'github' do
|
518
|
+
it 'github_from_url' do
|
519
|
+
url = 'https://github.com/datacite/bolognese'
|
505
520
|
response = subject.github_from_url(url)
|
506
|
-
expect(response).to eq(:
|
521
|
+
expect(response).to eq(owner: 'datacite', repo: 'bolognese')
|
507
522
|
end
|
508
523
|
|
509
|
-
it
|
510
|
-
url =
|
524
|
+
it 'github_from_url file' do
|
525
|
+
url = 'https://github.com/datacite/metadata-reports/blob/master/software/codemeta.json'
|
511
526
|
response = subject.github_from_url(url)
|
512
|
-
expect(response).to eq(:
|
527
|
+
expect(response).to eq(owner: 'datacite', repo: 'metadata-reports', release: 'master',
|
528
|
+
path: 'software/codemeta.json')
|
513
529
|
end
|
514
530
|
|
515
|
-
it
|
516
|
-
url =
|
531
|
+
it 'github_from_url cff file' do
|
532
|
+
url = 'https://github.com/citation-file-format/ruby-cff/blob/main/CITATION.cff'
|
517
533
|
response = subject.github_from_url(url)
|
518
|
-
expect(response).to eq(:
|
534
|
+
expect(response).to eq(owner: 'citation-file-format', path: 'CITATION.cff',
|
535
|
+
release: 'main', repo: 'ruby-cff')
|
519
536
|
end
|
520
537
|
|
521
|
-
it
|
522
|
-
url =
|
538
|
+
it 'github_as_codemeta_url' do
|
539
|
+
url = 'https://github.com/datacite/bolognese'
|
523
540
|
response = subject.github_as_codemeta_url(url)
|
524
|
-
expect(response).to eq(
|
541
|
+
expect(response).to eq('https://raw.githubusercontent.com/datacite/bolognese/master/codemeta.json')
|
525
542
|
end
|
526
543
|
|
527
|
-
it
|
528
|
-
url =
|
544
|
+
it 'github_as_cff_url' do
|
545
|
+
url = 'https://github.com/citation-file-format/ruby-cff'
|
529
546
|
response = subject.github_as_cff_url(url)
|
530
|
-
expect(response).to eq(
|
547
|
+
expect(response).to eq('https://raw.githubusercontent.com/citation-file-format/ruby-cff/main/CITATION.cff')
|
531
548
|
end
|
532
549
|
|
533
|
-
it
|
534
|
-
url =
|
550
|
+
it 'github_from_url file' do
|
551
|
+
url = 'https://github.com/datacite/metadata-reports/blob/master/software/codemeta.json'
|
535
552
|
response = subject.github_as_codemeta_url(url)
|
536
|
-
expect(response).to eq(
|
553
|
+
expect(response).to eq('https://raw.githubusercontent.com/datacite/metadata-reports/master/software/codemeta.json')
|
537
554
|
end
|
538
555
|
end
|
539
556
|
|
540
|
-
context
|
541
|
-
it
|
542
|
-
name =
|
557
|
+
context 'spdx' do
|
558
|
+
it 'name_to_spdx exists' do
|
559
|
+
name = 'Creative Commons Attribution 4.0 International'
|
543
560
|
response = subject.name_to_spdx(name)
|
544
|
-
expect(response).to eq({
|
561
|
+
expect(response).to eq({ 'rights' => 'Creative Commons Attribution 4.0 International',
|
562
|
+
'rightsUri' => 'https://creativecommons.org/licenses/by/4.0/legalcode', 'rightsIdentifier' => 'cc-by-4.0', 'rightsIdentifierScheme' => 'SPDX', 'schemeUri' => 'https://spdx.org/licenses/' })
|
545
563
|
end
|
546
564
|
|
547
|
-
it
|
548
|
-
name =
|
565
|
+
it 'name_to_spdx id' do
|
566
|
+
name = 'CC-BY-4.0'
|
549
567
|
response = subject.name_to_spdx(name)
|
550
|
-
expect(response).to eq({
|
568
|
+
expect(response).to eq({ 'rights' => 'Creative Commons Attribution 4.0 International',
|
569
|
+
'rightsUri' => 'https://creativecommons.org/licenses/by/4.0/legalcode', 'rightsIdentifier' => 'cc-by-4.0', 'rightsIdentifierScheme' => 'SPDX', 'schemeUri' => 'https://spdx.org/licenses/' })
|
551
570
|
end
|
552
571
|
|
553
|
-
it
|
554
|
-
hsh = {
|
572
|
+
it 'hsh_to_spdx id' do
|
573
|
+
hsh = { 'rightsIdentifier' => 'cc-by-4.0' }
|
555
574
|
response = subject.hsh_to_spdx(hsh)
|
556
|
-
expect(response).to eq({
|
575
|
+
expect(response).to eq({ 'rights' => 'Creative Commons Attribution 4.0 International',
|
576
|
+
'rightsUri' => 'https://creativecommons.org/licenses/by/4.0/legalcode', 'rightsIdentifier' => 'cc-by-4.0', 'rightsIdentifierScheme' => 'SPDX', 'schemeUri' => 'https://spdx.org/licenses/' })
|
557
577
|
end
|
558
578
|
|
559
|
-
it
|
560
|
-
hsh = {
|
579
|
+
it 'hsh_to_spdx url' do
|
580
|
+
hsh = { 'rightsURI' => 'http://creativecommons.org/licenses/by-nc/4.0/legalcode' }
|
561
581
|
response = subject.hsh_to_spdx(hsh)
|
562
|
-
expect(response).to eq(
|
582
|
+
expect(response).to eq(
|
583
|
+
'rights' => 'Creative Commons Attribution Non Commercial 4.0 International', 'rightsUri' => 'https://creativecommons.org/licenses/by-nc/4.0/legalcode', 'rightsIdentifier' => 'cc-by-nc-4.0', 'rightsIdentifierScheme' => 'SPDX', 'schemeUri' => 'https://spdx.org/licenses/'
|
584
|
+
)
|
563
585
|
end
|
564
586
|
|
565
|
-
it
|
566
|
-
hsh = {
|
587
|
+
it 'hsh_to_spdx not found' do
|
588
|
+
hsh = { 'rightsURI' => 'info:eu-repo/semantics/openAccess' }
|
567
589
|
response = subject.hsh_to_spdx(hsh)
|
568
|
-
expect(response).to eq({
|
590
|
+
expect(response).to eq({ 'rightsUri' => 'info:eu-repo/semantics/openAccess' })
|
569
591
|
end
|
570
592
|
end
|
571
593
|
|
572
|
-
context
|
573
|
-
it
|
574
|
-
name =
|
594
|
+
context 'fos' do
|
595
|
+
it 'name_to_fos match' do
|
596
|
+
name = 'Biological sciences'
|
575
597
|
response = subject.name_to_fos(name)
|
576
|
-
expect(response).to eq([{
|
577
|
-
|
578
|
-
|
579
|
-
|
598
|
+
expect(response).to eq([{ 'subject' => 'biological sciences' },
|
599
|
+
{ 'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf',
|
600
|
+
'subject' => 'FOS: Biological sciences',
|
601
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)' }])
|
580
602
|
end
|
581
603
|
|
582
|
-
it
|
583
|
-
name =
|
604
|
+
it 'name_to_fos for match' do
|
605
|
+
name = 'Statistics'
|
584
606
|
response = subject.name_to_fos(name)
|
585
|
-
expect(response).to eq([{
|
586
|
-
|
587
|
-
|
588
|
-
|
607
|
+
expect(response).to eq([{ 'subject' => 'statistics' },
|
608
|
+
{ 'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf',
|
609
|
+
'subject' => 'FOS: Mathematics',
|
610
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)' }])
|
589
611
|
end
|
590
612
|
|
591
|
-
it
|
592
|
-
name =
|
613
|
+
it 'name_to_fos no match' do
|
614
|
+
name = 'Random tag'
|
593
615
|
response = subject.name_to_fos(name)
|
594
|
-
expect(response).to eq([{
|
616
|
+
expect(response).to eq([{ 'subject' => 'random tag' }])
|
595
617
|
end
|
596
618
|
|
597
|
-
it
|
598
|
-
hsh = {
|
619
|
+
it 'hsh_to_fos match' do
|
620
|
+
hsh = { '__content__' => 'Biological sciences' }
|
599
621
|
response = subject.hsh_to_fos(hsh)
|
600
|
-
expect(response).to eq([{
|
601
|
-
|
602
|
-
|
603
|
-
|
622
|
+
expect(response).to eq([{ 'subject' => 'Biological sciences' },
|
623
|
+
{ 'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf',
|
624
|
+
'subject' => 'FOS: Biological sciences',
|
625
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)' }])
|
604
626
|
end
|
605
627
|
|
606
|
-
it
|
607
|
-
hsh = {
|
628
|
+
it 'hsh_to_fos for match' do
|
629
|
+
hsh = { '__content__' => 'Statistics' }
|
608
630
|
response = subject.hsh_to_fos(hsh)
|
609
|
-
expect(response).to eq([{
|
610
|
-
|
611
|
-
|
612
|
-
|
631
|
+
expect(response).to eq([{ 'subject' => 'Statistics' },
|
632
|
+
{ 'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf',
|
633
|
+
'subject' => 'FOS: Mathematics',
|
634
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)' }])
|
613
635
|
end
|
614
636
|
|
615
|
-
it
|
637
|
+
it 'hsh_to_fos for with schemeUri in hash' do
|
616
638
|
hsh = {
|
617
|
-
|
618
|
-
|
619
|
-
|
639
|
+
'subject' => 'FOS: Computer and information sciences',
|
640
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)',
|
641
|
+
'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf'
|
642
|
+
}
|
620
643
|
response = subject.hsh_to_fos(hsh)
|
621
644
|
expect(response).to eq([{
|
622
|
-
|
623
|
-
|
624
|
-
|
645
|
+
'subject' => 'FOS: Computer and information sciences',
|
646
|
+
'subjectScheme' => 'Fields of Science and Technology (FOS)',
|
647
|
+
'schemeUri' => 'http://www.oecd.org/science/inno/38235147.pdf'
|
648
|
+
}])
|
625
649
|
end
|
626
650
|
|
627
|
-
it
|
628
|
-
hsh = {
|
651
|
+
it 'hsh_to_fos no match' do
|
652
|
+
hsh = { '__content__' => 'Random tag' }
|
629
653
|
response = subject.hsh_to_fos(hsh)
|
630
|
-
expect(response).to eq([{
|
654
|
+
expect(response).to eq([{ 'subject' => 'Random tag' }])
|
631
655
|
end
|
632
656
|
end
|
633
657
|
|
634
|
-
context
|
635
|
-
it
|
636
|
-
prefix =
|
658
|
+
context 'random doi' do
|
659
|
+
it 'encode doi' do
|
660
|
+
prefix = '10.53731'
|
637
661
|
response = subject.encode_doi(prefix)
|
638
|
-
expect(response).to match(
|
662
|
+
expect(response).to match(%r{#{prefix}/[-._;()/:A-Za-z0-9]+})
|
639
663
|
expect(response.length).to eq(40)
|
640
664
|
end
|
641
665
|
|
642
|
-
it
|
643
|
-
doi =
|
666
|
+
it 'decode doi' do
|
667
|
+
doi = 'https://doi.org/10.53731/revzwnv-rpd913d-8drwz'
|
644
668
|
response = subject.decode_doi(doi)
|
645
|
-
expect(response).to eq
|
669
|
+
expect(response).to eq(30_286_005_717_401_267_192_153_432_991)
|
646
670
|
end
|
647
671
|
|
648
|
-
it
|
649
|
-
doi =
|
672
|
+
it 'decode anothe doi' do
|
673
|
+
doi = 'https://doi.org/10.53731/rckvde5-tzg61kj-7zvc1'
|
650
674
|
response = subject.decode_doi(doi)
|
651
|
-
expect(response).to eq
|
675
|
+
expect(response).to eq(30_198_793_950_250_854_133_601_922_433)
|
652
676
|
end
|
653
677
|
end
|
654
678
|
end
|