datacite-mapping 0.4.0 → 0.5.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/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/CHANGES.md +5 -1
- data/datacite-mapping.gemspec +5 -3
- data/lib/datacite/mapping/affiliation.rb +1 -1
- data/lib/datacite/mapping/contributor.rb +1 -1
- data/lib/datacite/mapping/contributor_name.rb +1 -1
- data/lib/datacite/mapping/creator_name.rb +1 -1
- data/lib/datacite/mapping/date.rb +8 -6
- data/lib/datacite/mapping/date_value.rb +2 -11
- data/lib/datacite/mapping/description.rb +1 -1
- data/lib/datacite/mapping/funding_reference.rb +2 -2
- data/lib/datacite/mapping/geo_location_box.rb +6 -6
- data/lib/datacite/mapping/geo_location_node.rb +2 -3
- data/lib/datacite/mapping/geo_location_point.rb +6 -4
- data/lib/datacite/mapping/geo_location_polygon.rb +1 -1
- data/lib/datacite/mapping/identifier.rb +1 -1
- data/lib/datacite/mapping/module_info.rb +2 -2
- data/lib/datacite/mapping/name_identifier.rb +1 -1
- data/lib/datacite/mapping/publisher.rb +1 -1
- data/lib/datacite/mapping/read_only_nodes.rb +3 -0
- data/lib/datacite/mapping/resource.rb +3 -3
- data/lib/datacite/mapping/subject.rb +1 -1
- data/lib/datacite/mapping/title.rb +1 -1
- data/spec/unit/datacite/mapping/date_value_spec.rb +1 -1
- data/spec/unit/datacite/mapping/resource_spec.rb +108 -109
- metadata +15 -15
@@ -53,22 +53,22 @@ module Datacite
|
|
53
53
|
describe '#identifier' do
|
54
54
|
it 'requires an identifier' do
|
55
55
|
args.delete(:identifier)
|
56
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
56
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'requires a non-nil identifier' do
|
60
60
|
args[:identifier] = nil
|
61
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
61
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'can be initialized' do
|
65
|
-
resource = Resource.new(args)
|
65
|
+
resource = Resource.new(**args)
|
66
66
|
expect(resource.identifier).to eq(identifier)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'can be set' do
|
70
70
|
new_id = Identifier.new(value: '10.1594/WDCC/CCSRNIES_SRES_B2')
|
71
|
-
resource = Resource.new(args)
|
71
|
+
resource = Resource.new(**args)
|
72
72
|
resource.identifier = new_id
|
73
73
|
expect(resource.identifier).to eq(new_id)
|
74
74
|
end
|
@@ -78,21 +78,21 @@ module Datacite
|
|
78
78
|
|
79
79
|
it 'requires a creator list' do
|
80
80
|
args.delete(:creators)
|
81
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
81
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'requires a non-nil creator list' do
|
85
85
|
args[:creators] = nil
|
86
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
86
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'requires a non-empty creator list' do
|
90
90
|
args[:creators] = []
|
91
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
91
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'can be initialized' do
|
95
|
-
resource = Resource.new(args)
|
95
|
+
resource = Resource.new(**args)
|
96
96
|
expect(resource.creators).to eq(creators)
|
97
97
|
end
|
98
98
|
|
@@ -102,7 +102,7 @@ module Datacite
|
|
102
102
|
identifier: NameIdentifier.new(scheme: 'ISNI', scheme_uri: URI('http://isni.org/'), value: '0000 0001 1678 4522'),
|
103
103
|
affiliations: ['Disney–ABC Television Group']
|
104
104
|
)]
|
105
|
-
resource = Resource.new(args)
|
105
|
+
resource = Resource.new(**args)
|
106
106
|
resource.creators = new_creators
|
107
107
|
expect(resource.creators).to eq(new_creators)
|
108
108
|
end
|
@@ -110,7 +110,7 @@ module Datacite
|
|
110
110
|
describe 'creator convenience methods' do
|
111
111
|
describe '#creator_names' do
|
112
112
|
it 'extracts the creator names' do
|
113
|
-
resource = Resource.new(args)
|
113
|
+
resource = Resource.new(**args)
|
114
114
|
expect(resource.creator_names)
|
115
115
|
.to eq(['Hedy Lamarr', 'Herschlag, Natalie'])
|
116
116
|
end
|
@@ -118,7 +118,7 @@ module Datacite
|
|
118
118
|
|
119
119
|
describe '#creator_affiliations' do
|
120
120
|
it 'extracts the creator affiliations' do
|
121
|
-
resource = Resource.new(args)
|
121
|
+
resource = Resource.new(**args)
|
122
122
|
expect(resource.creator_affiliations)
|
123
123
|
.to eq([
|
124
124
|
['United Artists', 'Metro-Goldwyn-Mayer'],
|
@@ -132,21 +132,21 @@ module Datacite
|
|
132
132
|
describe '#titles' do
|
133
133
|
it 'requires a title list' do
|
134
134
|
args.delete(:titles)
|
135
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
135
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'requires a non-nil title list' do
|
139
139
|
args[:titles] = nil
|
140
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
140
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'requires a non-empty title list' do
|
144
144
|
args[:titles] = []
|
145
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
145
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'can be initialized' do
|
149
|
-
resource = Resource.new(args)
|
149
|
+
resource = Resource.new(**args)
|
150
150
|
expect(resource.titles).to eq(titles)
|
151
151
|
end
|
152
152
|
|
@@ -156,7 +156,7 @@ module Datacite
|
|
156
156
|
type: TitleType::SUBTITLE,
|
157
157
|
value: 'Together with an Appendix of the Same, Containing an Answer to Some Objections, Made by Severall Persons against That Hypothesis'
|
158
158
|
)]
|
159
|
-
resource = Resource.new(args)
|
159
|
+
resource = Resource.new(**args)
|
160
160
|
resource.titles = new_titles
|
161
161
|
expect(resource.titles).to eq(new_titles)
|
162
162
|
end
|
@@ -166,22 +166,22 @@ module Datacite
|
|
166
166
|
describe '#publisher' do
|
167
167
|
it 'requires a publisher' do
|
168
168
|
args.delete(:publisher)
|
169
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
169
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
170
170
|
end
|
171
171
|
it 'requires a non-nil publisher' do
|
172
172
|
args[:publisher] = nil
|
173
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
173
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
174
174
|
end
|
175
175
|
it 'requires a non-blank publisher' do
|
176
176
|
expect { Publisher.new(value: ' ') }.to raise_error(ArgumentError)
|
177
177
|
end
|
178
178
|
it 'can be initialized' do
|
179
|
-
resource = Resource.new(args)
|
179
|
+
resource = Resource.new(**args)
|
180
180
|
expect(resource.publisher.value).to eq(publisher)
|
181
181
|
end
|
182
182
|
it 'can be set' do
|
183
183
|
new_publisher = 'University of California'
|
184
|
-
resource = Resource.new(args)
|
184
|
+
resource = Resource.new(**args)
|
185
185
|
resource.publisher = new_publisher
|
186
186
|
expect(resource.publisher.value).to eq(new_publisher)
|
187
187
|
end
|
@@ -189,11 +189,11 @@ module Datacite
|
|
189
189
|
args[:publisher] = Publisher.new(value: '
|
190
190
|
University of California
|
191
191
|
')
|
192
|
-
resource = Resource.new(args)
|
192
|
+
resource = Resource.new(**args)
|
193
193
|
expect(resource.publisher.value).to eq('University of California')
|
194
194
|
end
|
195
195
|
it 'strips on set' do
|
196
|
-
resource = Resource.new(args)
|
196
|
+
resource = Resource.new(**args)
|
197
197
|
resource.publisher = Publisher.new(value: '
|
198
198
|
University of California
|
199
199
|
')
|
@@ -204,31 +204,31 @@ module Datacite
|
|
204
204
|
describe '#publication_year' do
|
205
205
|
it 'requires a publication_year' do
|
206
206
|
args.delete(:publication_year)
|
207
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
207
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
208
208
|
end
|
209
209
|
it 'requires a non-nil publication_year' do
|
210
210
|
args[:publication_year] = nil
|
211
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
211
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
212
212
|
end
|
213
213
|
it 'requires a four-digit publication_year' do
|
214
214
|
args[:publication_year] = 999
|
215
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
215
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
216
216
|
args[:publication_year] = 10_000
|
217
|
-
expect { Resource.new(args) }.to raise_error(ArgumentError)
|
217
|
+
expect { Resource.new(**args) }.to raise_error(ArgumentError)
|
218
218
|
end
|
219
219
|
it 'can be initialized' do
|
220
|
-
resource = Resource.new(args)
|
220
|
+
resource = Resource.new(**args)
|
221
221
|
expect(resource.publication_year).to eq(publication_year)
|
222
222
|
end
|
223
223
|
it 'can be set' do
|
224
224
|
new_pub_year = 1963
|
225
|
-
resource = Resource.new(args)
|
225
|
+
resource = Resource.new(**args)
|
226
226
|
resource.publication_year = new_pub_year
|
227
227
|
expect(resource.publication_year).to eq(new_pub_year)
|
228
228
|
end
|
229
229
|
it 'converts strings to integers' do
|
230
230
|
new_pub_year = 1963
|
231
|
-
resource = Resource.new(args)
|
231
|
+
resource = Resource.new(**args)
|
232
232
|
resource.publication_year = new_pub_year.to_s
|
233
233
|
expect(resource.publication_year).to eq(new_pub_year)
|
234
234
|
end
|
@@ -236,7 +236,7 @@ module Datacite
|
|
236
236
|
|
237
237
|
describe '#subjects' do
|
238
238
|
it 'defaults to empty' do
|
239
|
-
resource = Resource.new(args)
|
239
|
+
resource = Resource.new(**args)
|
240
240
|
expect(resource.subjects).to eq([])
|
241
241
|
end
|
242
242
|
|
@@ -257,12 +257,12 @@ module Datacite
|
|
257
257
|
)
|
258
258
|
]
|
259
259
|
args[:subjects] = subjects
|
260
|
-
resource = Resource.new(args)
|
260
|
+
resource = Resource.new(**args)
|
261
261
|
expect(resource.subjects).to eq(subjects)
|
262
262
|
end
|
263
263
|
it 'can\'t be initialized to nil' do
|
264
264
|
args[:subjects] = nil
|
265
|
-
resource = Resource.new(args)
|
265
|
+
resource = Resource.new(**args)
|
266
266
|
expect(resource.subjects).to eq([])
|
267
267
|
end
|
268
268
|
|
@@ -273,7 +273,7 @@ module Datacite
|
|
273
273
|
Subject.allocate
|
274
274
|
]
|
275
275
|
args[:subjects] = subjects
|
276
|
-
resource = Resource.new(args)
|
276
|
+
resource = Resource.new(**args)
|
277
277
|
expect(resource.subjects).to eq([subjects[1]])
|
278
278
|
end
|
279
279
|
end
|
@@ -294,12 +294,12 @@ module Datacite
|
|
294
294
|
value: '571.8 Croissance, développement, reproduction biologique (fécondation, sexualité)'
|
295
295
|
)
|
296
296
|
]
|
297
|
-
resource = Resource.new(args)
|
297
|
+
resource = Resource.new(**args)
|
298
298
|
resource.subjects = subjects
|
299
299
|
expect(resource.subjects).to eq(subjects)
|
300
300
|
end
|
301
301
|
it 'can\'t be set to nil' do
|
302
|
-
resource = Resource.new(args)
|
302
|
+
resource = Resource.new(**args)
|
303
303
|
resource.subjects = nil
|
304
304
|
expect(resource.subjects).to eq([])
|
305
305
|
end
|
@@ -309,7 +309,7 @@ module Datacite
|
|
309
309
|
Subject.new(value: 'Mammals--Embryology'),
|
310
310
|
Subject.allocate
|
311
311
|
]
|
312
|
-
resource = Resource.new(args)
|
312
|
+
resource = Resource.new(**args)
|
313
313
|
resource.subjects = subjects
|
314
314
|
expect(resource.subjects).to eq([subjects[1]])
|
315
315
|
end
|
@@ -318,7 +318,7 @@ module Datacite
|
|
318
318
|
|
319
319
|
describe '#funding_references' do
|
320
320
|
it 'defaults to empty' do
|
321
|
-
resource = Resource.new(args)
|
321
|
+
resource = Resource.new(**args)
|
322
322
|
expect(resource.funding_references).to eq([])
|
323
323
|
end
|
324
324
|
|
@@ -329,19 +329,19 @@ module Datacite
|
|
329
329
|
FundingReference.new(name: 'НИИЧАВО', award_number: '164070')
|
330
330
|
]
|
331
331
|
args[:funding_references] = funding_references
|
332
|
-
resource = Resource.new(args)
|
332
|
+
resource = Resource.new(**args)
|
333
333
|
expect(resource.funding_references).to eq(funding_references)
|
334
334
|
end
|
335
335
|
it 'can\'t be initialized to nil' do
|
336
336
|
args[:funding_references] = nil
|
337
|
-
resource = Resource.new(args)
|
337
|
+
resource = Resource.new(**args)
|
338
338
|
expect(resource.funding_references).to eq([])
|
339
339
|
end
|
340
340
|
end
|
341
341
|
|
342
342
|
describe '#funding_references=' do
|
343
343
|
it 'can be set' do
|
344
|
-
resource = Resource.new(args)
|
344
|
+
resource = Resource.new(**args)
|
345
345
|
funding_references = [
|
346
346
|
FundingReference.new(name: 'Ministry of Magic', award_number: '9¾'),
|
347
347
|
FundingReference.new(name: 'НИИЧАВО', award_number: '164070')
|
@@ -350,7 +350,7 @@ module Datacite
|
|
350
350
|
expect(resource.funding_references).to eq(funding_references)
|
351
351
|
end
|
352
352
|
it 'can\'t be set to nil' do
|
353
|
-
resource = Resource.new(args)
|
353
|
+
resource = Resource.new(**args)
|
354
354
|
resource.funding_references = nil
|
355
355
|
expect(resource.funding_references).to eq([])
|
356
356
|
end
|
@@ -359,18 +359,18 @@ module Datacite
|
|
359
359
|
|
360
360
|
describe '#language' do
|
361
361
|
it 'defaults to nil' do
|
362
|
-
resource = Resource.new(args)
|
362
|
+
resource = Resource.new(**args)
|
363
363
|
expect(resource.language).to be_nil
|
364
364
|
end
|
365
365
|
|
366
366
|
it 'can be initialized' do
|
367
367
|
args[:language] = 'en-emodeng'
|
368
|
-
resource = Resource.new(args)
|
368
|
+
resource = Resource.new(**args)
|
369
369
|
expect(resource.language).to eq('en-emodeng')
|
370
370
|
end
|
371
371
|
|
372
372
|
it 'can be set' do
|
373
|
-
resource = Resource.new(args)
|
373
|
+
resource = Resource.new(**args)
|
374
374
|
resource.language = 'en-emodeng'
|
375
375
|
expect(resource.language).to eq('en-emodeng')
|
376
376
|
end
|
@@ -379,7 +379,7 @@ module Datacite
|
|
379
379
|
describe '#contributors' do
|
380
380
|
|
381
381
|
it 'defaults to empty' do
|
382
|
-
resource = Resource.new(args)
|
382
|
+
resource = Resource.new(**args)
|
383
383
|
expect(resource.funding_references).to eq([])
|
384
384
|
end
|
385
385
|
|
@@ -390,19 +390,19 @@ module Datacite
|
|
390
390
|
Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER)
|
391
391
|
]
|
392
392
|
args[:contributors] = contributors
|
393
|
-
resource = Resource.new(args)
|
393
|
+
resource = Resource.new(**args)
|
394
394
|
expect(resource.contributors).to eq(contributors)
|
395
395
|
end
|
396
396
|
it 'can\'t be initialized to nil' do
|
397
397
|
args[:contributors] = nil
|
398
|
-
resource = Resource.new(args)
|
398
|
+
resource = Resource.new(**args)
|
399
399
|
expect(resource.contributors).to eq([])
|
400
400
|
end
|
401
401
|
end
|
402
402
|
|
403
403
|
describe '#contributors=' do
|
404
404
|
it 'can be set' do
|
405
|
-
resource = Resource.new(args)
|
405
|
+
resource = Resource.new(**args)
|
406
406
|
contributors = [
|
407
407
|
Contributor.new(name: 'Hershlag, Natalie', type: ContributorType::PROJECT_MEMBER),
|
408
408
|
Contributor.new(name: 'Hedy Lamarr', type: ContributorType::RESEARCHER)
|
@@ -411,7 +411,7 @@ module Datacite
|
|
411
411
|
expect(resource.contributors).to eq(contributors)
|
412
412
|
end
|
413
413
|
it 'can\'t be set to nil' do
|
414
|
-
resource = Resource.new(args)
|
414
|
+
resource = Resource.new(**args)
|
415
415
|
resource.contributors = nil
|
416
416
|
expect(resource.contributors).to eq([])
|
417
417
|
end
|
@@ -419,7 +419,7 @@ module Datacite
|
|
419
419
|
|
420
420
|
describe 'contributor convenience methods' do
|
421
421
|
before(:each) do
|
422
|
-
@resource = Resource.new(args)
|
422
|
+
@resource = Resource.new(**args)
|
423
423
|
@funder = Contributor.new(
|
424
424
|
name: 'The Ministry of Magic',
|
425
425
|
identifier: NameIdentifier.new(
|
@@ -460,7 +460,7 @@ module Datacite
|
|
460
460
|
|
461
461
|
describe '#dates' do
|
462
462
|
it 'defaults to empty' do
|
463
|
-
resource = Resource.new(args)
|
463
|
+
resource = Resource.new(**args)
|
464
464
|
expect(resource.funding_references).to eq([])
|
465
465
|
end
|
466
466
|
|
@@ -471,19 +471,19 @@ module Datacite
|
|
471
471
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
472
472
|
]
|
473
473
|
args[:dates] = dates
|
474
|
-
resource = Resource.new(args)
|
474
|
+
resource = Resource.new(**args)
|
475
475
|
expect(resource.dates).to eq(dates)
|
476
476
|
end
|
477
477
|
it 'can\'t be initialized to nil' do
|
478
478
|
args[:dates] = nil
|
479
|
-
resource = Resource.new(args)
|
479
|
+
resource = Resource.new(**args)
|
480
480
|
expect(resource.dates).to eq([])
|
481
481
|
end
|
482
482
|
end
|
483
483
|
|
484
484
|
describe '#dates=' do
|
485
485
|
it 'can be set' do
|
486
|
-
resource = Resource.new(args)
|
486
|
+
resource = Resource.new(**args)
|
487
487
|
dates = [
|
488
488
|
Date.new(value: DateTime.new(1914, 8, 4, 11, 0o1, 6.0123, '+1'), type: DateType::AVAILABLE),
|
489
489
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
@@ -492,7 +492,7 @@ module Datacite
|
|
492
492
|
expect(resource.dates).to eq(dates)
|
493
493
|
end
|
494
494
|
it 'can\'t be set to nil' do
|
495
|
-
resource = Resource.new(args)
|
495
|
+
resource = Resource.new(**args)
|
496
496
|
resource.dates = nil
|
497
497
|
expect(resource.dates).to eq([])
|
498
498
|
end
|
@@ -503,13 +503,13 @@ module Datacite
|
|
503
503
|
it 'can be initialized' do
|
504
504
|
resource_type = ResourceType.new(resource_type_general: ResourceTypeGeneral::DATASET, value: 'Dataset')
|
505
505
|
args[:resource_type] = resource_type
|
506
|
-
resource = Resource.new(args)
|
506
|
+
resource = Resource.new(**args)
|
507
507
|
expect(resource.resource_type).to eq(resource_type)
|
508
508
|
end
|
509
509
|
|
510
510
|
it 'can be set' do
|
511
511
|
resource_type = ResourceType.new(resource_type_general: ResourceTypeGeneral::DATASET, value: 'Dataset')
|
512
|
-
resource = Resource.new(args)
|
512
|
+
resource = Resource.new(**args)
|
513
513
|
resource.resource_type = resource_type
|
514
514
|
expect(resource.resource_type).to eq(resource_type)
|
515
515
|
end
|
@@ -517,7 +517,7 @@ module Datacite
|
|
517
517
|
|
518
518
|
describe '#alternate_identifiers' do
|
519
519
|
it 'defaults to empty' do
|
520
|
-
resource = Resource.new(args)
|
520
|
+
resource = Resource.new(**args)
|
521
521
|
expect(resource.alternate_identifiers).to eq([])
|
522
522
|
end
|
523
523
|
|
@@ -528,19 +528,19 @@ module Datacite
|
|
528
528
|
AlternateIdentifier.new(type: 'URL', value: 'http://example.com')
|
529
529
|
]
|
530
530
|
args[:alternate_identifiers] = alternate_identifiers
|
531
|
-
resource = Resource.new(args)
|
531
|
+
resource = Resource.new(**args)
|
532
532
|
expect(resource.alternate_identifiers).to eq(alternate_identifiers)
|
533
533
|
end
|
534
534
|
it 'can\'t be initialized to nil' do
|
535
535
|
args[:alternate_identifiers] = nil
|
536
|
-
resource = Resource.new(args)
|
536
|
+
resource = Resource.new(**args)
|
537
537
|
expect(resource.alternate_identifiers).to eq([])
|
538
538
|
end
|
539
539
|
end
|
540
540
|
|
541
541
|
describe '#alternate_identifiers=' do
|
542
542
|
it 'can be set' do
|
543
|
-
resource = Resource.new(args)
|
543
|
+
resource = Resource.new(**args)
|
544
544
|
alternate_identifiers = [
|
545
545
|
AlternateIdentifier.new(type: 'URL', value: 'http://example.org'),
|
546
546
|
AlternateIdentifier.new(type: 'URL', value: 'http://example.com')
|
@@ -549,7 +549,7 @@ module Datacite
|
|
549
549
|
expect(resource.alternate_identifiers).to eq(alternate_identifiers)
|
550
550
|
end
|
551
551
|
it 'can\'t be set to nil' do
|
552
|
-
resource = Resource.new(args)
|
552
|
+
resource = Resource.new(**args)
|
553
553
|
resource.alternate_identifiers = nil
|
554
554
|
expect(resource.alternate_identifiers).to eq([])
|
555
555
|
end
|
@@ -558,7 +558,7 @@ module Datacite
|
|
558
558
|
|
559
559
|
describe '#related_identifiers' do
|
560
560
|
it 'defaults to empty' do
|
561
|
-
resource = Resource.new(args)
|
561
|
+
resource = Resource.new(**args)
|
562
562
|
expect(resource.related_identifiers).to eq([])
|
563
563
|
end
|
564
564
|
|
@@ -580,19 +580,19 @@ module Datacite
|
|
580
580
|
)
|
581
581
|
]
|
582
582
|
args[:related_identifiers] = related_identifiers
|
583
|
-
resource = Resource.new(args)
|
583
|
+
resource = Resource.new(**args)
|
584
584
|
expect(resource.related_identifiers).to eq(related_identifiers)
|
585
585
|
end
|
586
586
|
it 'can\'t be initialized to nil' do
|
587
587
|
args[:related_identifiers] = nil
|
588
|
-
resource = Resource.new(args)
|
588
|
+
resource = Resource.new(**args)
|
589
589
|
expect(resource.related_identifiers).to eq([])
|
590
590
|
end
|
591
591
|
end
|
592
592
|
|
593
593
|
describe '#related_identifiers=' do
|
594
594
|
it 'can be set' do
|
595
|
-
resource = Resource.new(args)
|
595
|
+
resource = Resource.new(**args)
|
596
596
|
related_identifiers = [
|
597
597
|
RelatedIdentifier.new(
|
598
598
|
identifier_type: RelatedIdentifierType::URL,
|
@@ -612,7 +612,7 @@ module Datacite
|
|
612
612
|
expect(resource.related_identifiers).to eq(related_identifiers)
|
613
613
|
end
|
614
614
|
it 'can\'t be set to nil' do
|
615
|
-
resource = Resource.new(args)
|
615
|
+
resource = Resource.new(**args)
|
616
616
|
resource.related_identifiers = nil
|
617
617
|
expect(resource.related_identifiers).to eq([])
|
618
618
|
end
|
@@ -621,7 +621,7 @@ module Datacite
|
|
621
621
|
|
622
622
|
describe '#sizes' do
|
623
623
|
it 'defaults to empty' do
|
624
|
-
resource = Resource.new(args)
|
624
|
+
resource = Resource.new(**args)
|
625
625
|
expect(resource.sizes).to eq([])
|
626
626
|
end
|
627
627
|
|
@@ -629,12 +629,12 @@ module Datacite
|
|
629
629
|
it 'can be initialized' do
|
630
630
|
sizes = %w[48K 128K]
|
631
631
|
args[:sizes] = sizes
|
632
|
-
resource = Resource.new(args)
|
632
|
+
resource = Resource.new(**args)
|
633
633
|
expect(resource.sizes).to eq(sizes)
|
634
634
|
end
|
635
635
|
it 'can\'t be initialized to nil' do
|
636
636
|
args[:sizes] = nil
|
637
|
-
resource = Resource.new(args)
|
637
|
+
resource = Resource.new(**args)
|
638
638
|
expect(resource.sizes).to eq([])
|
639
639
|
end
|
640
640
|
end
|
@@ -642,12 +642,12 @@ module Datacite
|
|
642
642
|
describe '#sizes=' do
|
643
643
|
it 'can be set' do
|
644
644
|
sizes = %w[48K 128K]
|
645
|
-
resource = Resource.new(args)
|
645
|
+
resource = Resource.new(**args)
|
646
646
|
resource.sizes = sizes
|
647
647
|
expect(resource.sizes).to eq(sizes)
|
648
648
|
end
|
649
649
|
it 'can\'t be set to nil' do
|
650
|
-
resource = Resource.new(args)
|
650
|
+
resource = Resource.new(**args)
|
651
651
|
resource.sizes = nil
|
652
652
|
expect(resource.sizes).to eq([])
|
653
653
|
end
|
@@ -656,7 +656,7 @@ module Datacite
|
|
656
656
|
|
657
657
|
describe '#formats' do
|
658
658
|
it 'defaults to empty' do
|
659
|
-
resource = Resource.new(args)
|
659
|
+
resource = Resource.new(**args)
|
660
660
|
expect(resource.formats).to eq([])
|
661
661
|
end
|
662
662
|
|
@@ -664,12 +664,12 @@ module Datacite
|
|
664
664
|
it 'can be initialized' do
|
665
665
|
formats = %w[D64 DSK]
|
666
666
|
args[:formats] = formats
|
667
|
-
resource = Resource.new(args)
|
667
|
+
resource = Resource.new(**args)
|
668
668
|
expect(resource.formats).to eq(formats)
|
669
669
|
end
|
670
670
|
it 'can\'t be initialized to nil' do
|
671
671
|
args[:formats] = nil
|
672
|
-
resource = Resource.new(args)
|
672
|
+
resource = Resource.new(**args)
|
673
673
|
expect(resource.formats).to eq([])
|
674
674
|
end
|
675
675
|
end
|
@@ -677,12 +677,12 @@ module Datacite
|
|
677
677
|
describe '#formats=' do
|
678
678
|
it 'can be set' do
|
679
679
|
formats = %w[D64 DSK]
|
680
|
-
resource = Resource.new(args)
|
680
|
+
resource = Resource.new(**args)
|
681
681
|
resource.formats = formats
|
682
682
|
expect(resource.formats).to eq(formats)
|
683
683
|
end
|
684
684
|
it 'can\'t be set to nil' do
|
685
|
-
resource = Resource.new(args)
|
685
|
+
resource = Resource.new(**args)
|
686
686
|
resource.formats = nil
|
687
687
|
expect(resource.formats).to eq([])
|
688
688
|
end
|
@@ -691,17 +691,17 @@ module Datacite
|
|
691
691
|
|
692
692
|
describe '#version' do
|
693
693
|
it 'defaults to nil' do
|
694
|
-
resource = Resource.new(args)
|
694
|
+
resource = Resource.new(**args)
|
695
695
|
expect(resource.version).to be_nil
|
696
696
|
end
|
697
697
|
it 'can be initialized' do
|
698
698
|
args[:version] = '9.2.2'
|
699
|
-
resource = Resource.new(args)
|
699
|
+
resource = Resource.new(**args)
|
700
700
|
expect(resource.version).to eq('9.2.2')
|
701
701
|
end
|
702
702
|
it 'can be set' do
|
703
703
|
new_version = '9.2.2'
|
704
|
-
resource = Resource.new(args)
|
704
|
+
resource = Resource.new(**args)
|
705
705
|
resource.version = new_version
|
706
706
|
expect(resource.version).to eq(new_version)
|
707
707
|
end
|
@@ -709,34 +709,34 @@ module Datacite
|
|
709
709
|
args[:version] = '
|
710
710
|
9.2.2
|
711
711
|
'
|
712
|
-
resource = Resource.new(args)
|
712
|
+
resource = Resource.new(**args)
|
713
713
|
expect(resource.version).to eq('9.2.2')
|
714
714
|
end
|
715
715
|
it 'strips on set' do
|
716
|
-
resource = Resource.new(args)
|
716
|
+
resource = Resource.new(**args)
|
717
717
|
resource.version = '
|
718
718
|
9.2.2
|
719
719
|
'
|
720
720
|
expect(resource.version).to eq('9.2.2')
|
721
721
|
end
|
722
722
|
it 'accepts a float' do
|
723
|
-
resource = Resource.new(args)
|
723
|
+
resource = Resource.new(**args)
|
724
724
|
resource.version = 9.2
|
725
725
|
expect(resource.version).to eq('9.2')
|
726
726
|
end
|
727
727
|
it 'accepts an integer' do
|
728
|
-
resource = Resource.new(args)
|
728
|
+
resource = Resource.new(**args)
|
729
729
|
resource.version = 9
|
730
730
|
expect(resource.version).to eq('9')
|
731
731
|
end
|
732
732
|
it 'can be initialized' do
|
733
733
|
args[:version] = '9.2.2'
|
734
|
-
resource = Resource.new(args)
|
734
|
+
resource = Resource.new(**args)
|
735
735
|
expect(resource.version).to eq('9.2.2')
|
736
736
|
end
|
737
737
|
it 'can be set to nil' do
|
738
738
|
args[:version] = '9.2.2'
|
739
|
-
resource = Resource.new(args)
|
739
|
+
resource = Resource.new(**args)
|
740
740
|
resource.version = nil
|
741
741
|
expect(resource.version).to be_nil
|
742
742
|
end
|
@@ -744,7 +744,7 @@ module Datacite
|
|
744
744
|
|
745
745
|
describe '#rights_list' do
|
746
746
|
it 'defaults to empty' do
|
747
|
-
resource = Resource.new(args)
|
747
|
+
resource = Resource.new(**args)
|
748
748
|
expect(resource.rights_list).to eq([])
|
749
749
|
end
|
750
750
|
|
@@ -755,19 +755,19 @@ module Datacite
|
|
755
755
|
Rights.new(value: 'This work is free of known copyright restrictions.', uri: URI('http://creativecommons.org/publicdomain/mark/1.0/'))
|
756
756
|
]
|
757
757
|
args[:rights_list] = rights_list
|
758
|
-
resource = Resource.new(args)
|
758
|
+
resource = Resource.new(**args)
|
759
759
|
expect(resource.rights_list).to eq(rights_list)
|
760
760
|
end
|
761
761
|
it 'can\'t be initialized to nil' do
|
762
762
|
args[:rights_list] = nil
|
763
|
-
resource = Resource.new(args)
|
763
|
+
resource = Resource.new(**args)
|
764
764
|
expect(resource.rights_list).to eq([])
|
765
765
|
end
|
766
766
|
end
|
767
767
|
|
768
768
|
describe '#rights_list=' do
|
769
769
|
it 'can be set' do
|
770
|
-
resource = Resource.new(args)
|
770
|
+
resource = Resource.new(**args)
|
771
771
|
rights_list = [
|
772
772
|
Rights.new(value: 'CC0 1.0 Universal', uri: URI('http://creativecommons.org/publicdomain/zero/1.0/')),
|
773
773
|
Rights.new(value: 'This work is free of known copyright restrictions.', uri: URI('http://creativecommons.org/publicdomain/mark/1.0/'))
|
@@ -777,7 +777,7 @@ module Datacite
|
|
777
777
|
end
|
778
778
|
|
779
779
|
it 'can\'t be set to nil' do
|
780
|
-
resource = Resource.new(args)
|
780
|
+
resource = Resource.new(**args)
|
781
781
|
resource.rights_list = nil
|
782
782
|
expect(resource.rights_list).to eq([])
|
783
783
|
end
|
@@ -787,7 +787,7 @@ module Datacite
|
|
787
787
|
|
788
788
|
describe '#descriptions' do
|
789
789
|
it 'defaults to empty' do
|
790
|
-
resource = Resource.new(args)
|
790
|
+
resource = Resource.new(**args)
|
791
791
|
expect(resource.descriptions).to eq([])
|
792
792
|
end
|
793
793
|
|
@@ -798,12 +798,12 @@ module Datacite
|
|
798
798
|
Description.new(language: 'en-us', type: DescriptionType::METHODS, value: 'unsound')
|
799
799
|
]
|
800
800
|
args[:descriptions] = descriptions
|
801
|
-
resource = Resource.new(args)
|
801
|
+
resource = Resource.new(**args)
|
802
802
|
expect(resource.descriptions).to eq(descriptions)
|
803
803
|
end
|
804
804
|
it 'can\'t be initialized to nil' do
|
805
805
|
args[:descriptions] = nil
|
806
|
-
resource = Resource.new(args)
|
806
|
+
resource = Resource.new(**args)
|
807
807
|
expect(resource.descriptions).to eq([])
|
808
808
|
end
|
809
809
|
|
@@ -814,7 +814,7 @@ module Datacite
|
|
814
814
|
Description.allocate
|
815
815
|
]
|
816
816
|
args[:descriptions] = descriptions
|
817
|
-
resource = Resource.new(args)
|
817
|
+
resource = Resource.new(**args)
|
818
818
|
expect(resource.descriptions).to eq([descriptions[1]])
|
819
819
|
end
|
820
820
|
end
|
@@ -825,12 +825,12 @@ module Datacite
|
|
825
825
|
Description.new(language: 'en-us', type: DescriptionType::ABSTRACT, value: 'Exterminate all the brutes!'),
|
826
826
|
Description.new(language: 'en-us', type: DescriptionType::METHODS, value: 'unsound')
|
827
827
|
]
|
828
|
-
resource = Resource.new(args)
|
828
|
+
resource = Resource.new(**args)
|
829
829
|
resource.descriptions = descriptions
|
830
830
|
expect(resource.descriptions).to eq(descriptions)
|
831
831
|
end
|
832
832
|
it 'can\'t be set to nil' do
|
833
|
-
resource = Resource.new(args)
|
833
|
+
resource = Resource.new(**args)
|
834
834
|
resource.descriptions = nil
|
835
835
|
expect(resource.descriptions).to eq([])
|
836
836
|
end
|
@@ -841,7 +841,7 @@ module Datacite
|
|
841
841
|
Description.new(language: 'en-us', type: DescriptionType::METHODS, value: 'unsound'),
|
842
842
|
Description.allocate
|
843
843
|
]
|
844
|
-
resource = Resource.new(args)
|
844
|
+
resource = Resource.new(**args)
|
845
845
|
resource.descriptions = descriptions
|
846
846
|
expect(resource.descriptions).to eq([descriptions[1]])
|
847
847
|
end
|
@@ -850,7 +850,7 @@ module Datacite
|
|
850
850
|
|
851
851
|
describe '#geo_locations' do
|
852
852
|
it 'defaults to empty' do
|
853
|
-
resource = Resource.new(args)
|
853
|
+
resource = Resource.new(**args)
|
854
854
|
expect(resource.geo_locations).to eq([])
|
855
855
|
end
|
856
856
|
|
@@ -861,12 +861,12 @@ module Datacite
|
|
861
861
|
GeoLocation.new(box: GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67))
|
862
862
|
]
|
863
863
|
args[:geo_locations] = geo_locations
|
864
|
-
resource = Resource.new(args)
|
864
|
+
resource = Resource.new(**args)
|
865
865
|
expect(resource.geo_locations).to eq(geo_locations)
|
866
866
|
end
|
867
867
|
it 'can\'t be initialized to nil' do
|
868
868
|
args[:geo_locations] = nil
|
869
|
-
resource = Resource.new(args)
|
869
|
+
resource = Resource.new(**args)
|
870
870
|
expect(resource.geo_locations).to eq([])
|
871
871
|
end
|
872
872
|
it 'ignores empty locations' do
|
@@ -876,14 +876,14 @@ module Datacite
|
|
876
876
|
GeoLocation.new
|
877
877
|
]
|
878
878
|
args[:geo_locations] = geo_locations
|
879
|
-
resource = Resource.new(args)
|
879
|
+
resource = Resource.new(**args)
|
880
880
|
expect(resource.geo_locations).to eq([geo_locations[1]])
|
881
881
|
end
|
882
882
|
end
|
883
883
|
|
884
884
|
describe '#geo_locations=' do
|
885
885
|
it 'can be set' do
|
886
|
-
resource = Resource.new(args)
|
886
|
+
resource = Resource.new(**args)
|
887
887
|
geo_locations = [
|
888
888
|
GeoLocation.new(point: GeoLocationPoint.new(47.61, -122.33)),
|
889
889
|
GeoLocation.new(box: GeoLocationBox.new(-33.45, -122.33, 47.61, -70.67))
|
@@ -892,12 +892,12 @@ module Datacite
|
|
892
892
|
expect(resource.geo_locations).to eq(geo_locations)
|
893
893
|
end
|
894
894
|
it 'can\'t be set to nil' do
|
895
|
-
resource = Resource.new(args)
|
895
|
+
resource = Resource.new(**args)
|
896
896
|
resource.geo_locations = nil
|
897
897
|
expect(resource.geo_locations).to eq([])
|
898
898
|
end
|
899
899
|
it 'ignores empty locations' do
|
900
|
-
resource = Resource.new(args)
|
900
|
+
resource = Resource.new(**args)
|
901
901
|
geo_locations = [
|
902
902
|
GeoLocation.new,
|
903
903
|
GeoLocation.new(point: GeoLocationPoint.new(47.61, -122.33)),
|
@@ -945,14 +945,13 @@ module Datacite
|
|
945
945
|
r3 = r2.gsub(/<resource (xmlns:xsi="[^"]+")\s+(xsi:schemaLocation="[^"]+")>/, '<resource \\2 \\1 xmlns="http://datacite.org/schema/kernel-3">') # fix missing namespace
|
946
946
|
r4 = r3.gsub(%r{(<identifier[^>]+>)\s*([^ ]+)\s*(</identifier>)}, '\\1\\2\\3') # trim identifiers
|
947
947
|
r5 = r4.gsub(%r{<([^>]+tude)>([0-9.-]+?)(0?)0+</\1>}, '<\\1>\\2\\3</\\1>') # strip trailing coordinate zeroes
|
948
|
-
r6 = r5.gsub(%r{<(geoLocation[^>]+)>[^<]+</\1>}) { |loc| loc.gsub(/([0-9
|
948
|
+
r6 = r5.gsub(%r{<(geoLocation[^>]+)>[^<]+</\1>}) { |loc| loc.gsub(/([0-9-]+\.[0-9]+?)0+([^0-9])/, '\\1\\2') } # strip trailing coordinate zeroes
|
949
949
|
r7 = r6.gsub(%r{<([A-Za-z]*)[^>]*>\s*</\1>}, '') # remove empty tag pairs
|
950
|
-
|
950
|
+
to_pretty(r7)
|
951
951
|
# if r8.include?('<br')
|
952
952
|
# trace = [r0, r1, r2, r3, r4, r5, r6, r7, r8].map { |r| r.include?('<br') }
|
953
953
|
# puts trace
|
954
954
|
# end
|
955
|
-
r8
|
956
955
|
end
|
957
956
|
|
958
957
|
def to_pretty(xml_text)
|
@@ -977,7 +976,7 @@ module Datacite
|
|
977
976
|
r3.gsub(%r{(<contributor[^>/]+>\s*)<contributor>([^<]+)</contributor>(\s*</contributor>)}, '\\1<contributorName>\\2</contributorName>\\3') # fix broken contributors
|
978
977
|
end
|
979
978
|
|
980
|
-
def it_round_trips(file:, mapping: :_default, fix_dash1: false)
|
979
|
+
def it_round_trips(file:, mapping: :_default, fix_dash1: false)
|
981
980
|
options = { mapping: mapping }
|
982
981
|
basename = File.basename(file)
|
983
982
|
xml_text = xml_text_from(file, fix_dash1)
|