datacite-mapping 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +23 -11
- data/.ruby-version +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile +2 -0
- data/LICENSE.md +1 -1
- data/README.md +2 -2
- data/Rakefile +5 -3
- data/datacite-mapping.gemspec +9 -7
- data/examples/reading.rb +1 -1
- data/examples/writing.rb +1 -0
- data/lib/datacite/mapping.rb +2 -0
- data/lib/datacite/mapping/alternate_identifier.rb +4 -2
- data/lib/datacite/mapping/contributor.rb +5 -3
- data/lib/datacite/mapping/creator.rb +6 -4
- data/lib/datacite/mapping/date.rb +5 -5
- data/lib/datacite/mapping/date_value.rb +4 -2
- data/lib/datacite/mapping/description.rb +5 -3
- data/lib/datacite/mapping/empty_filtering_nodes.rb +2 -0
- data/lib/datacite/mapping/funding_reference.rb +6 -4
- data/lib/datacite/mapping/geo_location.rb +2 -0
- data/lib/datacite/mapping/geo_location_box.rb +12 -10
- data/lib/datacite/mapping/geo_location_node.rb +9 -7
- data/lib/datacite/mapping/geo_location_point.rb +8 -6
- data/lib/datacite/mapping/geo_location_polygon.rb +3 -1
- data/lib/datacite/mapping/identifier.rb +9 -7
- data/lib/datacite/mapping/module_info.rb +5 -3
- data/lib/datacite/mapping/name_identifier.rb +4 -2
- data/lib/datacite/mapping/namespace_extensions.rb +2 -0
- data/lib/datacite/mapping/read_only_nodes.rb +5 -3
- data/lib/datacite/mapping/related_identifier.rb +5 -3
- data/lib/datacite/mapping/resource.rb +15 -13
- data/lib/datacite/mapping/resource_type.rb +3 -1
- data/lib/datacite/mapping/rights.rb +3 -1
- data/lib/datacite/mapping/subject.rb +5 -3
- data/lib/datacite/mapping/title.rb +5 -3
- data/spec/.rubocop.yml +3 -0
- data/spec/rspec_custom_matchers.rb +8 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/contributor_spec.rb +2 -0
- data/spec/unit/datacite/mapping/creator_spec.rb +2 -0
- data/spec/unit/datacite/mapping/date_spec.rb +2 -0
- data/spec/unit/datacite/mapping/date_value_spec.rb +2 -0
- data/spec/unit/datacite/mapping/description_spec.rb +2 -0
- data/spec/unit/datacite/mapping/funding_reference_spec.rb +3 -1
- data/spec/unit/datacite/mapping/geo_location_box_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_point_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_polygon_spec.rb +22 -20
- data/spec/unit/datacite/mapping/geo_location_spec.rb +24 -22
- data/spec/unit/datacite/mapping/identifier_spec.rb +8 -6
- data/spec/unit/datacite/mapping/name_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/related_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/resource_spec.rb +22 -18
- data/spec/unit/datacite/mapping/rights_spec.rb +3 -1
- data/spec/unit/datacite/mapping/subject_spec.rb +2 -0
- data/spec/unit/datacite/mapping/title_spec.rb +2 -0
- metadata +26 -26
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -56,7 +58,7 @@ module Datacite
|
|
56
58
|
<funderIdentifier funderIdentifierType="Crossref Funder ID">http://doi.org/10.13039/501100000780</funderIdentifier>
|
57
59
|
<awardNumber awardURI="http://cordis.europa.eu/project/rcn/100180_en.html">282625</awardNumber>
|
58
60
|
<awardTitle>MOTivational strength of ecosystem services and alternative ways to express the value of BIOdiversity</awardTitle>
|
59
|
-
</fundingReference>'
|
61
|
+
</fundingReference>'
|
60
62
|
|
61
63
|
@fref = FundingReference.parse_xml(fref_xml)
|
62
64
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -6,17 +8,17 @@ module Datacite
|
|
6
8
|
describe '#==' do
|
7
9
|
it 'reports equal values as equal' do
|
8
10
|
polygon1 = GeoLocationPolygon.new(points: [
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
12
|
+
GeoLocationPoint.new(33.45, -122.33),
|
13
|
+
GeoLocationPoint.new(33.45, 122.33),
|
14
|
+
GeoLocationPoint.new(-33.45, -122.33)
|
15
|
+
])
|
14
16
|
polygon2 = GeoLocationPolygon.new(points: [
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
18
|
+
GeoLocationPoint.new(33.45, -122.33),
|
19
|
+
GeoLocationPoint.new(33.45, 122.33),
|
20
|
+
GeoLocationPoint.new(-33.45, -122.33)
|
21
|
+
])
|
20
22
|
expect(polygon1).to eq(polygon2)
|
21
23
|
expect(polygon1.hash).to eq(polygon2.hash)
|
22
24
|
expect(polygon2).to eq(polygon1)
|
@@ -25,17 +27,17 @@ module Datacite
|
|
25
27
|
|
26
28
|
it 'reports unequal values as unequal' do
|
27
29
|
polygon1 = GeoLocationPolygon.new(points: [
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
31
|
+
GeoLocationPoint.new(33.45, -122.33),
|
32
|
+
GeoLocationPoint.new(33.45, 122.33),
|
33
|
+
GeoLocationPoint.new(-33.45, -122.33)
|
34
|
+
])
|
33
35
|
polygon2 = GeoLocationPolygon.new(points: [
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
GeoLocationPoint.new(33.45, 122.33),
|
37
|
+
GeoLocationPoint.new(-33.45, 122.33),
|
38
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
39
|
+
GeoLocationPoint.new(33.45, 122.33)
|
40
|
+
])
|
39
41
|
expect(polygon1).not_to eq(polygon2)
|
40
42
|
expect(polygon1.hash).not_to eq(polygon2.hash)
|
41
43
|
expect(polygon2).not_to eq(polygon1)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -45,11 +47,11 @@ module Datacite
|
|
45
47
|
end
|
46
48
|
it 'accepts a polygon' do
|
47
49
|
polygon = GeoLocationPolygon.new(points: [
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
GeoLocationPoint.new(47.61, -122.33),
|
51
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
52
|
+
GeoLocationPoint.new(47.61, -70.67),
|
53
|
+
GeoLocationPoint.new(47.61, -122.33)
|
54
|
+
])
|
53
55
|
loc = GeoLocation.new(polygon: polygon)
|
54
56
|
expect(loc.polygon).to eq(polygon)
|
55
57
|
end
|
@@ -106,11 +108,11 @@ module Datacite
|
|
106
108
|
describe '#polygon=' do
|
107
109
|
it 'sets the polygon' do
|
108
110
|
polygon = GeoLocationPolygon.new(points: [
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
GeoLocationPoint.new(47.61, -122.33),
|
112
|
+
GeoLocationPoint.new(-33.45, -122.33),
|
113
|
+
GeoLocationPoint.new(47.61, -70.67),
|
114
|
+
GeoLocationPoint.new(47.61, -122.33)
|
115
|
+
])
|
114
116
|
loc = GeoLocation.new
|
115
117
|
loc.polygon = polygon
|
116
118
|
expect(loc.polygon).to eq(polygon)
|
@@ -168,11 +170,11 @@ module Datacite
|
|
168
170
|
expect(loc.place).to eq('Atlantic Ocean')
|
169
171
|
actual_polygon = loc.polygon
|
170
172
|
expected_polygon = GeoLocationPolygon.new(points: [
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
GeoLocationPoint.new(31.233, -67.302),
|
174
|
+
GeoLocationPoint.new(-68.211, -71.032),
|
175
|
+
GeoLocationPoint.new(42.893, 41.09),
|
176
|
+
GeoLocationPoint.new(31.233, -67.302)
|
177
|
+
])
|
176
178
|
expect(actual_polygon).to eq(expected_polygon)
|
177
179
|
end
|
178
180
|
|
@@ -196,12 +198,12 @@ module Datacite
|
|
196
198
|
point: GeoLocationPoint.new(31.233, -67.302),
|
197
199
|
box: GeoLocationBox.new(41.09, -71.032, 42.893, -68.211),
|
198
200
|
place: 'Atlantic Ocean',
|
199
|
-
polygon:
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
201
|
+
polygon: GeoLocationPolygon.new(points: [
|
202
|
+
GeoLocationPoint.new(-67.302, 31.233),
|
203
|
+
GeoLocationPoint.new(-71.032, -68.211),
|
204
|
+
GeoLocationPoint.new(41.09, 42.893),
|
205
|
+
GeoLocationPoint.new(-67.302, 31.233)
|
206
|
+
])
|
205
207
|
)
|
206
208
|
end
|
207
209
|
|
@@ -257,7 +259,7 @@ module Datacite
|
|
257
259
|
|
258
260
|
it 'writes DC3 in XSD-defined order: point, box, place' do
|
259
261
|
actual_xml = loc.save_to_xml(mapping: :datacite_3)
|
260
|
-
expected_order = %w
|
262
|
+
expected_order = %w[geoLocationPoint geoLocationBox geoLocationPlace]
|
261
263
|
actual_order = actual_xml.children.map(&:name)
|
262
264
|
expect(actual_order).to eq(expected_order)
|
263
265
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -21,13 +23,13 @@ module Datacite
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'disallows bad DOIs' do
|
24
|
-
bad_dois = %w
|
26
|
+
bad_dois = %w[
|
25
27
|
20.14749/1407399495
|
26
28
|
11.14749/1407399495
|
27
29
|
10./1407399495
|
28
30
|
10.14749\1407399495
|
29
31
|
10.14749/
|
30
|
-
|
32
|
+
]
|
31
33
|
bad_dois.each do |doi|
|
32
34
|
expect { Identifier.new(value: doi) }.to raise_error(ArgumentError)
|
33
35
|
end
|
@@ -71,13 +73,13 @@ module Datacite
|
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'raises ArgumentError if it is passed a bad DOI' do
|
74
|
-
bad_dois = %w
|
76
|
+
bad_dois = %w[
|
75
77
|
20.14749/1407399495
|
76
78
|
11.14749/1407399495
|
77
79
|
10./1407399495
|
78
80
|
10.14749\1407399495
|
79
81
|
10.14749/
|
80
|
-
|
82
|
+
]
|
81
83
|
bad_dois.each do |doi|
|
82
84
|
expect { Identifier.from_doi(doi) }.to raise_error do |e|
|
83
85
|
expect(e).to be_an(ArgumentError)
|
@@ -95,13 +97,13 @@ module Datacite
|
|
95
97
|
end
|
96
98
|
it 'disallows bad DOIs' do
|
97
99
|
id = Identifier.allocate
|
98
|
-
bad_dois = %w
|
100
|
+
bad_dois = %w[
|
99
101
|
20.14749/1407399495
|
100
102
|
11.14749/1407399495
|
101
103
|
10./1407399495
|
102
104
|
10.14749\1407399495
|
103
105
|
10.14749/
|
104
|
-
|
106
|
+
]
|
105
107
|
bad_dois.each do |doi|
|
106
108
|
expect { id.value = doi }.to raise_error(ArgumentError)
|
107
109
|
expect(id.value).to be_nil
|
@@ -1,5 +1,8 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'spec_helper'
|
5
|
+
require 'tmpdir'
|
3
6
|
|
4
7
|
module Datacite
|
5
8
|
module Mapping
|
@@ -119,9 +122,9 @@ module Datacite
|
|
119
122
|
resource = Resource.new(args)
|
120
123
|
expect(resource.creator_affiliations)
|
121
124
|
.to eq([
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
+
['United Artists', 'Metro-Goldwyn-Mayer'],
|
126
|
+
['Gaumont Buena Vista International', '20th Century Fox']
|
127
|
+
])
|
125
128
|
end
|
126
129
|
end
|
127
130
|
end
|
@@ -228,7 +231,7 @@ module Datacite
|
|
228
231
|
it 'converts strings to integers' do
|
229
232
|
new_pub_year = 1963
|
230
233
|
resource = Resource.new(args)
|
231
|
-
resource.publication_year =
|
234
|
+
resource.publication_year = new_pub_year.to_s
|
232
235
|
expect(resource.publication_year).to eq(new_pub_year)
|
233
236
|
end
|
234
237
|
end
|
@@ -426,7 +429,8 @@ module Datacite
|
|
426
429
|
scheme_uri: URI('http://iatistandard.org/201/codelists/OrganisationIdentifier/'),
|
427
430
|
value: 'GR-9¾'
|
428
431
|
),
|
429
|
-
type: ContributorType::FUNDER
|
432
|
+
type: ContributorType::FUNDER
|
433
|
+
)
|
430
434
|
@resource.contributors << @funder
|
431
435
|
end
|
432
436
|
|
@@ -465,7 +469,7 @@ module Datacite
|
|
465
469
|
describe 'dates:' do
|
466
470
|
it 'can be initialized' do
|
467
471
|
dates = [
|
468
|
-
Date.new(value: DateTime.new(1914, 8, 4, 11,
|
472
|
+
Date.new(value: DateTime.new(1914, 8, 4, 11, 0o1, 6.0123, '+1'), type: DateType::AVAILABLE),
|
469
473
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
470
474
|
]
|
471
475
|
args[:dates] = dates
|
@@ -483,7 +487,7 @@ module Datacite
|
|
483
487
|
it 'can be set' do
|
484
488
|
resource = Resource.new(args)
|
485
489
|
dates = [
|
486
|
-
Date.new(value: DateTime.new(1914, 8, 4, 11,
|
490
|
+
Date.new(value: DateTime.new(1914, 8, 4, 11, 0o1, 6.0123, '+1'), type: DateType::AVAILABLE),
|
487
491
|
Date.new(value: '1914-08-04T11:01:06.0123+01:00', type: DateType::AVAILABLE)
|
488
492
|
]
|
489
493
|
resource.dates = dates
|
@@ -625,7 +629,7 @@ module Datacite
|
|
625
629
|
|
626
630
|
describe 'sizes:' do
|
627
631
|
it 'can be initialized' do
|
628
|
-
sizes = %w
|
632
|
+
sizes = %w[48K 128K]
|
629
633
|
args[:sizes] = sizes
|
630
634
|
resource = Resource.new(args)
|
631
635
|
expect(resource.sizes).to eq(sizes)
|
@@ -639,7 +643,7 @@ module Datacite
|
|
639
643
|
|
640
644
|
describe '#sizes=' do
|
641
645
|
it 'can be set' do
|
642
|
-
sizes = %w
|
646
|
+
sizes = %w[48K 128K]
|
643
647
|
resource = Resource.new(args)
|
644
648
|
resource.sizes = sizes
|
645
649
|
expect(resource.sizes).to eq(sizes)
|
@@ -660,7 +664,7 @@ module Datacite
|
|
660
664
|
|
661
665
|
describe 'formats:' do
|
662
666
|
it 'can be initialized' do
|
663
|
-
formats = %w
|
667
|
+
formats = %w[D64 DSK]
|
664
668
|
args[:formats] = formats
|
665
669
|
resource = Resource.new(args)
|
666
670
|
expect(resource.formats).to eq(formats)
|
@@ -674,7 +678,7 @@ module Datacite
|
|
674
678
|
|
675
679
|
describe '#formats=' do
|
676
680
|
it 'can be set' do
|
677
|
-
formats = %w
|
681
|
+
formats = %w[D64 DSK]
|
678
682
|
resource = Resource.new(args)
|
679
683
|
resource.formats = formats
|
680
684
|
expect(resource.formats).to eq(formats)
|
@@ -940,7 +944,7 @@ module Datacite
|
|
940
944
|
r1 = r0.gsub(%r{<br\s+/>}, '<br/>') # entity-de-escape <br/> tags
|
941
945
|
# r2 = r1.gsub(%r{<(?!br)[^>]+/>}, '') # remove empty tags
|
942
946
|
r2 = r1
|
943
|
-
r3 = r2.gsub(/<resource (xmlns:xsi="[^"]+")\s+(xsi:schemaLocation="[^"]+")>/,
|
947
|
+
r3 = r2.gsub(/<resource (xmlns:xsi="[^"]+")\s+(xsi:schemaLocation="[^"]+")>/, '<resource \\2 \\1 xmlns="http://datacite.org/schema/kernel-3">') # fix missing namespace
|
944
948
|
r4 = r3.gsub(%r{(<identifier[^>]+>)\s*([^ ]+)\s*(</identifier>)}, '\\1\\2\\3') # trim identifiers
|
945
949
|
r5 = r4.gsub(%r{<([^>]+tude)>([0-9.-]+?)(0?)0+</\1>}, '<\\1>\\2\\3</\\1>') # strip trailing coordinate zeroes
|
946
950
|
r6 = r5.gsub(%r{<(geoLocation[^>]+)>[^<]+</\1>}) { |loc| loc.gsub(/([0-9\-]+\.[0-9]+?)0+([^0-9])/, '\\1\\2') } # strip trailing coordinate zeroes
|
@@ -1017,7 +1021,7 @@ module Datacite
|
|
1017
1021
|
matches = warnings_including(substring)
|
1018
1022
|
found_count = matches.size
|
1019
1023
|
msg = "expected #{count} warnings including '#{substring}', found #{found_count}"
|
1020
|
-
msg
|
1024
|
+
msg += ": #{matches}" if include_matches
|
1021
1025
|
expect(found_count).to eq(count), msg
|
1022
1026
|
end
|
1023
1027
|
|
@@ -1025,7 +1029,7 @@ module Datacite
|
|
1025
1029
|
matches = REXML::XPath.match(rexml, xpath)
|
1026
1030
|
found_count = matches.size
|
1027
1031
|
msg = "expected #{count} matches for XPath '#{xpath}', found #{found_count}"
|
1028
|
-
msg
|
1032
|
+
msg += ": #{matches}" if include_matches
|
1029
1033
|
expect(found_count).to eq(count), msg
|
1030
1034
|
end
|
1031
1035
|
|
@@ -1033,7 +1037,7 @@ module Datacite
|
|
1033
1037
|
@warnings = []
|
1034
1038
|
allow(ReadOnlyNodes).to receive(:warn) do |w|
|
1035
1039
|
warnings << w
|
1036
|
-
Kernel.warn(w) # for debugging
|
1040
|
+
# Kernel.warn(w) # for debugging
|
1037
1041
|
end
|
1038
1042
|
|
1039
1043
|
xml = File.read('spec/data/datacite-4-synthetic.xml')
|
@@ -1051,7 +1055,7 @@ module Datacite
|
|
1051
1055
|
end
|
1052
1056
|
|
1053
1057
|
it 'warns about givenNames and familyNames' do
|
1054
|
-
name_tags = %w
|
1058
|
+
name_tags = %w[givenName familyName]
|
1055
1059
|
name_tags.each do |tag|
|
1056
1060
|
expect_matches("//#{tag}", 0, true)
|
1057
1061
|
expect_warning(tag, 1)
|
@@ -1151,7 +1155,7 @@ module Datacite
|
|
1151
1155
|
|
1152
1156
|
describe '#save_to_file' do
|
1153
1157
|
it 'saves to a file' do
|
1154
|
-
xml_text =
|
1158
|
+
xml_text = File.read('spec/data/datacite4/datacite-example-full-v4.0.xml')
|
1155
1159
|
resource = Resource.parse_xml(xml_text)
|
1156
1160
|
Dir.mktmpdir('resource_spec') do |dir|
|
1157
1161
|
path = "#{dir}/resource.xml"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -80,7 +82,7 @@ module Datacite
|
|
80
82
|
expected_xml = '<rights rightsURI="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International (CC BY 4.0)</rights>'
|
81
83
|
expect(rights.save_to_xml).to be_xml(expected_xml)
|
82
84
|
|
83
|
-
[
|
85
|
+
%i[CC_ZERO CC_BY].each do |c|
|
84
86
|
r = Rights.const_get(c)
|
85
87
|
puts "#{c.to_s.downcase.gsub('_zero', '0')}:"
|
86
88
|
puts " uri: #{r.uri}"
|