datacite-mapping 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +4 -0
  3. data/CHANGES.md +15 -0
  4. data/README.md +8 -3
  5. data/datacite-mapping.gemspec +2 -3
  6. data/lib/datacite/mapping.rb +1 -1
  7. data/lib/datacite/mapping/affiliation.rb +44 -0
  8. data/lib/datacite/mapping/alternate_identifier.rb +2 -0
  9. data/lib/datacite/mapping/contributor.rb +32 -6
  10. data/lib/datacite/mapping/contributor_name.rb +42 -0
  11. data/lib/datacite/mapping/creator.rb +39 -7
  12. data/lib/datacite/mapping/creator_name.rb +42 -0
  13. data/lib/datacite/mapping/date.rb +12 -0
  14. data/lib/datacite/mapping/date_value.rb +6 -0
  15. data/lib/datacite/mapping/description.rb +6 -2
  16. data/lib/datacite/mapping/empty_filtering_nodes.rb +1 -0
  17. data/lib/datacite/mapping/funding_reference.rb +14 -1
  18. data/lib/datacite/mapping/geo_location.rb +6 -1
  19. data/lib/datacite/mapping/geo_location_box.rb +5 -0
  20. data/lib/datacite/mapping/geo_location_node.rb +4 -2
  21. data/lib/datacite/mapping/geo_location_point.rb +3 -0
  22. data/lib/datacite/mapping/geo_location_polygon.rb +10 -1
  23. data/lib/datacite/mapping/identifier.rb +11 -9
  24. data/lib/datacite/mapping/module_info.rb +2 -2
  25. data/lib/datacite/mapping/name_identifier.rb +10 -6
  26. data/lib/datacite/mapping/name_type.rb +18 -0
  27. data/lib/datacite/mapping/publisher.rb +42 -0
  28. data/lib/datacite/mapping/read_only_nodes.rb +4 -0
  29. data/lib/datacite/mapping/related_identifier.rb +38 -1
  30. data/lib/datacite/mapping/resource.rb +25 -11
  31. data/lib/datacite/mapping/resource_type.rb +4 -0
  32. data/lib/datacite/mapping/rights.rb +33 -6
  33. data/lib/datacite/mapping/subject.rb +3 -2
  34. data/lib/datacite/mapping/title.rb +3 -2
  35. data/spec/data/datacite4/{datacite-example-Box_dateCollected_DataCollector-v4.0.xml → datacite-example-Box_dateCollected_DataCollector-v4.xml} +9 -11
  36. data/spec/data/datacite4/{datacite-example-GeoLocation-v4.0.xml → datacite-example-GeoLocation-v4.xml} +11 -10
  37. data/spec/data/datacite4/{datacite-example-HasMetadata-v4.0.xml → datacite-example-HasMetadata-v4.xml} +18 -13
  38. data/spec/data/datacite4/{datacite-example-ResearchGroup_Methods-v4.0.xml → datacite-example-ResearchGroup_Methods-v4.xml} +14 -12
  39. data/spec/data/datacite4/{datacite-example-ResourceTypeGeneral_Collection-v4.0.xml → datacite-example-ResourceTypeGeneral_Collection-v4.xml} +9 -9
  40. data/spec/data/datacite4/datacite-example-affiliation-v4.xml +114 -0
  41. data/spec/data/datacite4/{datacite-example-complicated-v4.0.xml → datacite-example-complicated-v4.xml} +14 -11
  42. data/spec/data/datacite4/datacite-example-datapaper-v4.xml +32 -0
  43. data/spec/data/datacite4/{datacite-example-dataset-v4.0.xml → datacite-example-dataset-v4.xml} +20 -14
  44. data/spec/data/datacite4/datacite-example-full-v4.xml +114 -0
  45. data/spec/data/datacite4/{datacite-example-fundingReference-v.4.0.xml → datacite-example-fundingReference-v4.xml} +16 -13
  46. data/spec/data/datacite4/datacite-example-polygon-advanced-v4.xml +141 -0
  47. data/spec/data/datacite4/datacite-example-polygon-v4.xml +161 -0
  48. data/spec/data/datacite4/{datacite-example-relationTypeIsIdenticalTo-v4.0.xml → datacite-example-relationTypeIsIdenticalTo-v4.xml} +17 -17
  49. data/spec/data/datacite4/datacite-example-software-v4.xml +66 -0
  50. data/spec/data/datacite4/{datacite-example-video-v4.0.xml → datacite-example-video-v4.xml} +7 -7
  51. data/spec/data/datacite4/{datacite-example-workflow-v4.0.xml → datacite-example-workflow-v4.xml} +13 -11
  52. data/spec/data/datacite4/metadata.xsd +102 -57
  53. data/spec/rspec_custom_matchers.rb +3 -0
  54. data/spec/unit/datacite/mapping/contributor_spec.rb +7 -1
  55. data/spec/unit/datacite/mapping/creator_spec.rb +9 -3
  56. data/spec/unit/datacite/mapping/resource_spec.rb +14 -17
  57. data/spec/unit/datacite/mapping/rights_spec.rb +0 -13
  58. metadata +42 -28
  59. data/spec/data/datacite4/datacite-example-full-v4.0.xml +0 -71
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'spec_helper'
@@ -174,32 +173,31 @@ module Datacite
174
173
  expect { Resource.new(args) }.to raise_error(ArgumentError)
175
174
  end
176
175
  it 'requires a non-blank publisher' do
177
- args[:publisher] = "\n \n"
178
- expect { Resource.new(args) }.to raise_error(ArgumentError)
176
+ expect { Publisher.new(value: ' ') }.to raise_error(ArgumentError)
179
177
  end
180
178
  it 'can be initialized' do
181
179
  resource = Resource.new(args)
182
- expect(resource.publisher).to eq(publisher)
180
+ expect(resource.publisher.value).to eq(publisher)
183
181
  end
184
182
  it 'can be set' do
185
183
  new_publisher = 'University of California'
186
184
  resource = Resource.new(args)
187
185
  resource.publisher = new_publisher
188
- expect(resource.publisher).to eq(new_publisher)
186
+ expect(resource.publisher.value).to eq(new_publisher)
189
187
  end
190
188
  it 'strips on initialization' do
191
- args[:publisher] = '
189
+ args[:publisher] = Publisher.new(value: '
192
190
  University of California
193
- '
191
+ ')
194
192
  resource = Resource.new(args)
195
- expect(resource.publisher).to eq('University of California')
193
+ expect(resource.publisher.value).to eq('University of California')
196
194
  end
197
195
  it 'strips on set' do
198
196
  resource = Resource.new(args)
199
- resource.publisher = '
197
+ resource.publisher = Publisher.new(value: '
200
198
  University of California
201
- '
202
- expect(resource.publisher).to eq('University of California')
199
+ ')
200
+ expect(resource.publisher.value).to eq('University of California')
203
201
  end
204
202
  end
205
203
 
@@ -922,7 +920,7 @@ module Datacite
922
920
  end
923
921
 
924
922
  def parse_file(xml_text, basename)
925
- return Resource.parse_xml(xml_text)
923
+ Resource.parse_xml(xml_text)
926
924
  rescue Exception => e # rubocop:disable Lint/RescueException
927
925
  warn "Error parsing #{basename}: #{e}"
928
926
  File.open("tmp/#{basename}-xml_text.xml", 'w') { |t| t.write(xml_text) }
@@ -933,7 +931,7 @@ module Datacite
933
931
  def write_xml(resource, basename, options)
934
932
  # Workaround for Dash 1 datacite.xml with missing DOI
935
933
  resource.identifier = Identifier.from_doi('10.5555/12345678') unless resource.identifier
936
- return resource.write_xml(options)
934
+ resource.write_xml(options)
937
935
  rescue Exception => e # rubocop:disable Lint/RescueException
938
936
  warn "Error writing #{basename}: #{e}"
939
937
  raise
@@ -988,11 +986,10 @@ module Datacite
988
986
  actual_xml = write_xml(resource, basename, options)
989
987
  expected_xml.gsub!(/(<resource[^>]+>)\s+(<creators>)/, "\\1\n <identifier identifierType=\"DOI\">10.5555/12345678</identifier>\n \\2") if fix_dash1
990
988
  begin
991
- # actual_xml = actual_xml.gsub('&apos;', "'")
992
989
  expect(actual_xml).to be_xml(expected_xml)
993
990
  rescue Exception # rubocop:disable Lint/RescueException
994
- File.open("tmp/#{basename}-expected.xml", 'w') { |t| t.write(expected_xml) }
995
- File.open("tmp/#{basename}-actual.xml", 'w') { |t| t.write(actual_xml) }
991
+ File.open("/tmp/#{basename}-expected.xml", 'w') { |t| t.write(expected_xml) }
992
+ File.open("/tmp/#{basename}-actual.xml", 'w') { |t| t.write(actual_xml) }
996
993
  raise
997
994
  end
998
995
  end
@@ -1155,7 +1152,7 @@ module Datacite
1155
1152
 
1156
1153
  describe '#save_to_file' do
1157
1154
  it 'saves to a file' do
1158
- xml_text = File.read('spec/data/datacite4/datacite-example-full-v4.0.xml')
1155
+ xml_text = File.read('spec/data/datacite4/datacite-example-full-v4.xml')
1159
1156
  resource = Resource.parse_xml(xml_text)
1160
1157
  Dir.mktmpdir('resource_spec') do |dir|
1161
1158
  path = "#{dir}/resource.xml"
@@ -14,9 +14,6 @@ module Datacite
14
14
  rights = Rights.new(value: 'CC0 1.0 Universal', uri: URI('http://creativecommons.org/publicdomain/zero/1.0/'))
15
15
  expect(rights.uri).to eq(URI('http://creativecommons.org/publicdomain/zero/1.0/'))
16
16
  end
17
- it 'requires a value' do
18
- expect { Rights.new(uri: URI('http://creativecommons.org/publicdomain/zero/1.0/')) }.to raise_error(ArgumentError)
19
- end
20
17
  end
21
18
 
22
19
  describe '#value=' do
@@ -25,16 +22,6 @@ module Datacite
25
22
  rights.value = 'CC0 1.0 Universal'
26
23
  expect(rights.value).to eq('CC0 1.0 Universal')
27
24
  end
28
- it 'requires a value' do
29
- rights = Rights.new(value: 'CC0 1.0 Universal')
30
- expect { rights.value = nil }.to raise_error(ArgumentError)
31
- expect(rights.value).to eq('CC0 1.0 Universal')
32
- end
33
- it 'requires a non-empty value' do
34
- rights = Rights.new(value: 'CC0 1.0 Universal')
35
- expect { rights.value = '' }.to raise_error(ArgumentError)
36
- expect(rights.value).to eq('CC0 1.0 Universal')
37
- end
38
25
  end
39
26
 
40
27
  describe '#uri=' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacite-mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typesafe_enum
@@ -211,9 +211,12 @@ files:
211
211
  - examples/reading.rb
212
212
  - examples/writing.rb
213
213
  - lib/datacite/mapping.rb
214
+ - lib/datacite/mapping/affiliation.rb
214
215
  - lib/datacite/mapping/alternate_identifier.rb
215
216
  - lib/datacite/mapping/contributor.rb
217
+ - lib/datacite/mapping/contributor_name.rb
216
218
  - lib/datacite/mapping/creator.rb
219
+ - lib/datacite/mapping/creator_name.rb
217
220
  - lib/datacite/mapping/date.rb
218
221
  - lib/datacite/mapping/date_value.rb
219
222
  - lib/datacite/mapping/description.rb
@@ -227,7 +230,9 @@ files:
227
230
  - lib/datacite/mapping/identifier.rb
228
231
  - lib/datacite/mapping/module_info.rb
229
232
  - lib/datacite/mapping/name_identifier.rb
233
+ - lib/datacite/mapping/name_type.rb
230
234
  - lib/datacite/mapping/namespace_extensions.rb
235
+ - lib/datacite/mapping/publisher.rb
231
236
  - lib/datacite/mapping/read_only_nodes.rb
232
237
  - lib/datacite/mapping/related_identifier.rb
233
238
  - lib/datacite/mapping/resource.rb
@@ -400,18 +405,23 @@ files:
400
405
  - spec/data/datacite3/datacite-example-video-v3.0.xml
401
406
  - spec/data/datacite3/datacite-example-workflow-v3.0.xml
402
407
  - spec/data/datacite3/metadata.xsd
403
- - spec/data/datacite4/datacite-example-Box_dateCollected_DataCollector-v4.0.xml
404
- - spec/data/datacite4/datacite-example-GeoLocation-v4.0.xml
405
- - spec/data/datacite4/datacite-example-HasMetadata-v4.0.xml
406
- - spec/data/datacite4/datacite-example-ResearchGroup_Methods-v4.0.xml
407
- - spec/data/datacite4/datacite-example-ResourceTypeGeneral_Collection-v4.0.xml
408
- - spec/data/datacite4/datacite-example-complicated-v4.0.xml
409
- - spec/data/datacite4/datacite-example-dataset-v4.0.xml
410
- - spec/data/datacite4/datacite-example-full-v4.0.xml
411
- - spec/data/datacite4/datacite-example-fundingReference-v.4.0.xml
412
- - spec/data/datacite4/datacite-example-relationTypeIsIdenticalTo-v4.0.xml
413
- - spec/data/datacite4/datacite-example-video-v4.0.xml
414
- - spec/data/datacite4/datacite-example-workflow-v4.0.xml
408
+ - spec/data/datacite4/datacite-example-Box_dateCollected_DataCollector-v4.xml
409
+ - spec/data/datacite4/datacite-example-GeoLocation-v4.xml
410
+ - spec/data/datacite4/datacite-example-HasMetadata-v4.xml
411
+ - spec/data/datacite4/datacite-example-ResearchGroup_Methods-v4.xml
412
+ - spec/data/datacite4/datacite-example-ResourceTypeGeneral_Collection-v4.xml
413
+ - spec/data/datacite4/datacite-example-affiliation-v4.xml
414
+ - spec/data/datacite4/datacite-example-complicated-v4.xml
415
+ - spec/data/datacite4/datacite-example-datapaper-v4.xml
416
+ - spec/data/datacite4/datacite-example-dataset-v4.xml
417
+ - spec/data/datacite4/datacite-example-full-v4.xml
418
+ - spec/data/datacite4/datacite-example-fundingReference-v4.xml
419
+ - spec/data/datacite4/datacite-example-polygon-advanced-v4.xml
420
+ - spec/data/datacite4/datacite-example-polygon-v4.xml
421
+ - spec/data/datacite4/datacite-example-relationTypeIsIdenticalTo-v4.xml
422
+ - spec/data/datacite4/datacite-example-software-v4.xml
423
+ - spec/data/datacite4/datacite-example-video-v4.xml
424
+ - spec/data/datacite4/datacite-example-workflow-v4.xml
415
425
  - spec/data/datacite4/metadata.xsd
416
426
  - spec/rspec_custom_matchers.rb
417
427
  - spec/spec_helper.rb
@@ -452,8 +462,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
452
462
  - !ruby/object:Gem::Version
453
463
  version: '0'
454
464
  requirements: []
455
- rubyforge_project:
456
- rubygems_version: 2.6.12
465
+ rubygems_version: 3.0.2
457
466
  signing_key:
458
467
  specification_version: 4
459
468
  summary: Parses and generates Datacite XML documents
@@ -623,18 +632,23 @@ test_files:
623
632
  - spec/data/datacite3/datacite-example-video-v3.0.xml
624
633
  - spec/data/datacite3/datacite-example-workflow-v3.0.xml
625
634
  - spec/data/datacite3/metadata.xsd
626
- - spec/data/datacite4/datacite-example-Box_dateCollected_DataCollector-v4.0.xml
627
- - spec/data/datacite4/datacite-example-GeoLocation-v4.0.xml
628
- - spec/data/datacite4/datacite-example-HasMetadata-v4.0.xml
629
- - spec/data/datacite4/datacite-example-ResearchGroup_Methods-v4.0.xml
630
- - spec/data/datacite4/datacite-example-ResourceTypeGeneral_Collection-v4.0.xml
631
- - spec/data/datacite4/datacite-example-complicated-v4.0.xml
632
- - spec/data/datacite4/datacite-example-dataset-v4.0.xml
633
- - spec/data/datacite4/datacite-example-full-v4.0.xml
634
- - spec/data/datacite4/datacite-example-fundingReference-v.4.0.xml
635
- - spec/data/datacite4/datacite-example-relationTypeIsIdenticalTo-v4.0.xml
636
- - spec/data/datacite4/datacite-example-video-v4.0.xml
637
- - spec/data/datacite4/datacite-example-workflow-v4.0.xml
635
+ - spec/data/datacite4/datacite-example-Box_dateCollected_DataCollector-v4.xml
636
+ - spec/data/datacite4/datacite-example-GeoLocation-v4.xml
637
+ - spec/data/datacite4/datacite-example-HasMetadata-v4.xml
638
+ - spec/data/datacite4/datacite-example-ResearchGroup_Methods-v4.xml
639
+ - spec/data/datacite4/datacite-example-ResourceTypeGeneral_Collection-v4.xml
640
+ - spec/data/datacite4/datacite-example-affiliation-v4.xml
641
+ - spec/data/datacite4/datacite-example-complicated-v4.xml
642
+ - spec/data/datacite4/datacite-example-datapaper-v4.xml
643
+ - spec/data/datacite4/datacite-example-dataset-v4.xml
644
+ - spec/data/datacite4/datacite-example-full-v4.xml
645
+ - spec/data/datacite4/datacite-example-fundingReference-v4.xml
646
+ - spec/data/datacite4/datacite-example-polygon-advanced-v4.xml
647
+ - spec/data/datacite4/datacite-example-polygon-v4.xml
648
+ - spec/data/datacite4/datacite-example-relationTypeIsIdenticalTo-v4.xml
649
+ - spec/data/datacite4/datacite-example-software-v4.xml
650
+ - spec/data/datacite4/datacite-example-video-v4.xml
651
+ - spec/data/datacite4/datacite-example-workflow-v4.xml
638
652
  - spec/data/datacite4/metadata.xsd
639
653
  - spec/rspec_custom_matchers.rb
640
654
  - spec/spec_helper.rb
@@ -1,71 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datacite.org/schema/kernel-4" xsi:schemaLocation="http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd">
3
- <identifier identifierType="DOI">10.5072/example-full</identifier>
4
- <creators>
5
- <creator>
6
- <creatorName>Miller, Elizabeth</creatorName>
7
- <givenName>Elizabeth</givenName>
8
- <familyName>Miller</familyName>
9
- <nameIdentifier schemeURI="http://orcid.org/" nameIdentifierScheme="ORCID">0000-0001-5000-0007</nameIdentifier>
10
- <affiliation>DataCite</affiliation>
11
- </creator>
12
- </creators>
13
- <titles>
14
- <title xml:lang="en-us">Full DataCite XML Example</title>
15
- <title xml:lang="en-us" titleType="Subtitle">Demonstration of DataCite Properties.</title>
16
- </titles>
17
- <publisher>DataCite</publisher>
18
- <publicationYear>2014</publicationYear>
19
- <subjects>
20
- <subject xml:lang="en-us" schemeURI="http://dewey.info/" subjectScheme="dewey">000 computer science</subject>
21
- </subjects>
22
- <contributors>
23
- <contributor contributorType="ProjectLeader">
24
- <contributorName>Starr, Joan</contributorName>
25
- <nameIdentifier schemeURI="http://orcid.org/" nameIdentifierScheme="ORCID">0000-0002-7285-027X</nameIdentifier>
26
- <affiliation>California Digital Library</affiliation>
27
- </contributor>
28
- </contributors>
29
- <dates>
30
- <date dateType="Updated">2014-10-17</date>
31
- </dates>
32
- <language>en-us</language>
33
- <resourceType resourceTypeGeneral="Software">XML</resourceType>
34
- <alternateIdentifiers>
35
- <alternateIdentifier alternateIdentifierType="URL">http://schema.datacite.org/schema/meta/kernel-3.1/example/datacite-example-full-v3.1.xml</alternateIdentifier>
36
- </alternateIdentifiers>
37
- <relatedIdentifiers>
38
- <relatedIdentifier relatedIdentifierType="URL" relationType="HasMetadata" relatedMetadataScheme="citeproc+json" schemeURI="https://github.com/citation-style-language/schema/raw/master/csl-data.json">http://data.datacite.org/application/citeproc+json/10.5072/example-full</relatedIdentifier>
39
- <relatedIdentifier relatedIdentifierType="arXiv" relationType="IsReviewedBy">arXiv:0706.0001</relatedIdentifier>
40
- </relatedIdentifiers>
41
- <sizes>
42
- <size>3KB</size>
43
- </sizes>
44
- <formats>
45
- <format>application/xml</format>
46
- </formats>
47
- <version>3.1</version>
48
- <rightsList>
49
- <rights rightsURI="http://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0 Universal</rights>
50
- </rightsList>
51
- <descriptions>
52
- <description xml:lang="en-us" descriptionType="Abstract">
53
- XML example of all DataCite Metadata Schema v4.0 properties.
54
- </description>
55
- </descriptions>
56
- <geoLocations>
57
- <geoLocation>
58
- <geoLocationPlace>Atlantic Ocean</geoLocationPlace>
59
- <geoLocationPoint>
60
- <pointLongitude>-67.302</pointLongitude>
61
- <pointLatitude>31.233</pointLatitude>
62
- </geoLocationPoint>
63
- <geoLocationBox>
64
- <westBoundLongitude>-71.032</westBoundLongitude>
65
- <eastBoundLongitude>-68.211</eastBoundLongitude>
66
- <southBoundLatitude>41.090</southBoundLatitude>
67
- <northBoundLatitude>42.893</northBoundLatitude>
68
- </geoLocationBox>
69
- </geoLocation>
70
- </geoLocations>
71
- </resource>