datacite-mapping 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -2
- data/CHANGES.md +8 -1
- data/README.md +20 -21
- data/datacite-mapping.gemspec +2 -2
- data/examples/reading.rb +1 -2
- data/examples/writing.rb +1 -4
- data/lib/datacite/mapping/module_info.rb +1 -1
- data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +1 -2
- data/spec/unit/datacite/mapping/contributor_spec.rb +2 -4
- data/spec/unit/datacite/mapping/creator_spec.rb +2 -4
- data/spec/unit/datacite/mapping/description_spec.rb +6 -12
- data/spec/unit/datacite/mapping/geo_location_spec.rb +2 -4
- data/spec/unit/datacite/mapping/identifier_spec.rb +1 -2
- data/spec/unit/datacite/mapping/name_identifier_spec.rb +1 -2
- data/spec/unit/datacite/mapping/related_identifier_spec.rb +1 -2
- data/spec/unit/datacite/mapping/resource_spec.rb +1 -2
- data/spec/unit/datacite/mapping/resource_type_spec.rb +1 -2
- data/spec/unit/datacite/mapping/rights_spec.rb +2 -4
- data/spec/unit/datacite/mapping/subject_spec.rb +2 -4
- data/spec/unit/datacite/mapping/title_spec.rb +3 -6
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57920b6deb33af54ffc30bbce3cf2943f069b74d
|
4
|
+
data.tar.gz: 7864e0a91b9034cbb949df41b374c7700294c37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfc67fba2953a659de6c9d6068fa242896fb3c35c32b140db9a56aeadc89ee6e13d218c76aac1636dcf4c1edaad09e006eecfcb4892a8b14a53d5e1320aeee18
|
7
|
+
data.tar.gz: 0a42d5ac00ed8af6307a5fc4dc97def2dd5ec086fe3cd1bd22a2797abb586c94188bbd34cd59ee4f45ef94c61362397bf05bb243a2cc4b1d14cd66b1b8f3e51f
|
data/.gitignore
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.1.1 (14 Dec 2015)
|
2
|
+
|
3
|
+
- Update to [XML::MappingExtensions](https://github.com/dmolesUC3/xml-mapping_extensions) 0.3.2, allowing
|
4
|
+
use of [#parse_xml](http://www.rubydoc.info/github/dmolesUC3/xml-mapping_extensions/master/XML/Mapping/ClassMethods#parse_xml-instance_method)
|
5
|
+
and [#write_xml](http://www.rubydoc.info/github/dmolesUC3/xml-mapping_extensions/master/XML/Mapping#write_xml-instance_method)
|
6
|
+
in examples and tests
|
7
|
+
|
1
8
|
## 0.1.0 (10 Dec 2015)
|
2
9
|
|
3
|
-
- Initial release
|
10
|
+
- Initial release
|
data/README.md
CHANGED
@@ -15,23 +15,25 @@ require 'datacite/mapping'
|
|
15
15
|
|
16
16
|
include Datacite::Mapping
|
17
17
|
|
18
|
-
|
19
|
-
resource = Resource.
|
20
|
-
|
21
|
-
|
22
|
-
citation
|
23
|
-
citation << ' '
|
24
|
-
citation <<
|
25
|
-
citation <<
|
26
|
-
|
27
|
-
|
28
|
-
citation <<
|
29
|
-
citation <<
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
File.open('resource.xml', 'r') do |xml_file|
|
19
|
+
resource = Resource.parse_xml(xml_file)
|
20
|
+
|
21
|
+
creators = resource.creators
|
22
|
+
citation = ''
|
23
|
+
citation << creators.map(&:name).join('; ')
|
24
|
+
citation << ' '
|
25
|
+
citation << "(#{resource.publication_year})"
|
26
|
+
citation << ': '
|
27
|
+
title = resource.titles[0].value
|
28
|
+
citation << title
|
29
|
+
citation << (title.end_with?('.') ? ' ' : '. ')
|
30
|
+
citation << resource.publisher
|
31
|
+
|
32
|
+
puts("Citation: #{citation}")
|
33
|
+
|
34
|
+
abstract = resource.descriptions.find { |d| d.type = DescriptionType::ABSTRACT }
|
35
|
+
puts("Abstract: #{abstract.value}")
|
36
|
+
end
|
35
37
|
```
|
36
38
|
|
37
39
|
Results:
|
@@ -110,10 +112,7 @@ resource = Resource.new(
|
|
110
112
|
]
|
111
113
|
)
|
112
114
|
|
113
|
-
|
114
|
-
formatter = REXML::Formatters::Pretty.new
|
115
|
-
formatter.compact = true
|
116
|
-
formatter.write(xml, $stdout)
|
115
|
+
puts resource.write_xml
|
117
116
|
```
|
118
117
|
|
119
118
|
Results:
|
data/datacite-mapping.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
|
-
require '
|
5
|
+
require 'uri'
|
6
6
|
require 'datacite/mapping/module_info'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ['lib']
|
25
25
|
|
26
26
|
spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.2'
|
27
|
-
spec.add_dependency 'xml-mapping_extensions', '~> 0.3'
|
27
|
+
spec.add_dependency 'xml-mapping_extensions', '~> 0.3', '>= 0.3.2'
|
28
28
|
|
29
29
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
30
30
|
spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
|
data/examples/reading.rb
CHANGED
@@ -55,8 +55,7 @@ xml_text = '<?xml version="1.0" encoding="UTF-8"?>
|
|
55
55
|
</geoLocations>
|
56
56
|
</resource>'
|
57
57
|
|
58
|
-
|
59
|
-
resource = Resource.load_from_xml(xml.root)
|
58
|
+
resource = Resource.parse_xml(xml_text)
|
60
59
|
|
61
60
|
creators = resource.creators
|
62
61
|
citation = ''
|
data/examples/writing.rb
CHANGED
@@ -41,8 +41,7 @@ module Datacite
|
|
41
41
|
describe '#load_from_xml' do
|
42
42
|
it 'parses XML' do
|
43
43
|
xml_text = '<alternateIdentifier alternateIdentifierType="URL">http://schema.datacite.org/schema/meta/kernel-3.1/example/datacite-example-full-v3.1.xml</alternateIdentifier>'
|
44
|
-
|
45
|
-
id = AlternateIdentifier.load_from_xml(xml)
|
44
|
+
id = AlternateIdentifier.parse_xml(xml_text)
|
46
45
|
expect(id.type).to eq('URL')
|
47
46
|
expect(id.value).to eq('http://schema.datacite.org/schema/meta/kernel-3.1/example/datacite-example-full-v3.1.xml')
|
48
47
|
end
|
@@ -88,8 +88,7 @@ module Datacite
|
|
88
88
|
<affiliation>Gaumont Buena Vista International</affiliation>
|
89
89
|
<affiliation>20th Century Fox</affiliation>
|
90
90
|
</contributor>'
|
91
|
-
|
92
|
-
contributor = Contributor.load_from_xml(xml)
|
91
|
+
contributor = Contributor.parse_xml(xml_text)
|
93
92
|
expect(contributor.name).to eq('Hershlag, Natalie')
|
94
93
|
expect(contributor.affiliations).to eq(['Gaumont Buena Vista International', '20th Century Fox'])
|
95
94
|
id = contributor.identifier
|
@@ -105,8 +104,7 @@ module Datacite
|
|
105
104
|
<contributorName>Hedy Lamarr</contributorName>
|
106
105
|
<nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
|
107
106
|
</contributor>'
|
108
|
-
|
109
|
-
contributor = Contributor.load_from_xml(xml)
|
107
|
+
contributor = Contributor.parse_xml(xml_text)
|
110
108
|
expect(contributor.affiliations).to eq([])
|
111
109
|
end
|
112
110
|
end
|
@@ -86,8 +86,7 @@ module Datacite
|
|
86
86
|
<affiliation>United Artists</affiliation>
|
87
87
|
<affiliation>Metro-Goldwyn-Mayer</affiliation>
|
88
88
|
</creator>'
|
89
|
-
|
90
|
-
creator = Creator.load_from_xml(xml)
|
89
|
+
creator = Creator.parse_xml(xml_text)
|
91
90
|
expect(creator.name).to eq('Hedy Lamarr')
|
92
91
|
expect(creator.affiliations).to eq(['United Artists', 'Metro-Goldwyn-Mayer'])
|
93
92
|
id = creator.identifier
|
@@ -101,8 +100,7 @@ module Datacite
|
|
101
100
|
<creatorName>Hedy Lamarr</creatorName>
|
102
101
|
<nameIdentifier schemeURI="http://isni.org/" nameIdentifierScheme="ISNI">0000-0001-1690-159X</nameIdentifier>
|
103
102
|
</creator>'
|
104
|
-
|
105
|
-
creator = Creator.load_from_xml(xml)
|
103
|
+
creator = Creator.parse_xml(xml_text)
|
106
104
|
expect(creator.affiliations).to eq([])
|
107
105
|
end
|
108
106
|
end
|
@@ -8,8 +8,7 @@ module Datacite
|
|
8
8
|
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
9
9
|
XML example of all DataCite Metadata Schema v3.1 properties.
|
10
10
|
</description>'
|
11
|
-
|
12
|
-
desc = Description.load_from_xml(xml)
|
11
|
+
desc = Description.parse_xml(xml_text)
|
13
12
|
|
14
13
|
expected_lang = 'en-us'
|
15
14
|
expected_type = DescriptionType::ABSTRACT
|
@@ -24,8 +23,7 @@ module Datacite
|
|
24
23
|
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
25
24
|
<p>This is HTML text</p><p><small>despite the advice in the standard</small></p>
|
26
25
|
</description>'
|
27
|
-
|
28
|
-
desc = Description.load_from_xml(xml)
|
26
|
+
desc = Description.parse_xml(xml_text)
|
29
27
|
|
30
28
|
expected_value = '<p>This is HTML text</p><p><small>despite the advice in the standard</small></p>'
|
31
29
|
expect(desc.value).to eq(expected_value)
|
@@ -35,8 +33,7 @@ module Datacite
|
|
35
33
|
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">
|
36
34
|
This is the value
|
37
35
|
</description>'
|
38
|
-
|
39
|
-
desc = Description.load_from_xml(xml)
|
36
|
+
desc = Description.parse_xml(xml_text)
|
40
37
|
expect(desc.value).to eq('This is the value')
|
41
38
|
end
|
42
39
|
|
@@ -44,8 +41,7 @@ module Datacite
|
|
44
41
|
xml_text = '<description descriptionType="Abstract">
|
45
42
|
I am an <br></br> abstract <br/> full <br/> of <br/>s
|
46
43
|
</description>'
|
47
|
-
|
48
|
-
desc = Description.load_from_xml(xml)
|
44
|
+
desc = Description.parse_xml(xml_text)
|
49
45
|
expected_value = 'I am an <br/> abstract <br/> full <br/> of <br/>s'
|
50
46
|
expect(desc.value.strip).to eq(expected_value)
|
51
47
|
end
|
@@ -71,15 +67,13 @@ module Datacite
|
|
71
67
|
|
72
68
|
it 'round-trips to XML' do
|
73
69
|
xml_text = '<description xml:lang="en-us" descriptionType="Abstract">foo</description>'
|
74
|
-
|
75
|
-
desc = Description.load_from_xml(xml)
|
70
|
+
desc = Description.parse_xml(xml_text)
|
76
71
|
expect(desc.save_to_xml).to be_xml(xml_text)
|
77
72
|
end
|
78
73
|
|
79
74
|
it 'un-escapes <br/> tags when round-tripping' do
|
80
75
|
xml_text = '<description xml:lang="en-us" descriptionType="Abstract"><br/> <br/> abstract <br></br> full <br /> of <br> </br>s</description>'
|
81
|
-
|
82
|
-
desc = Description.load_from_xml(xml)
|
76
|
+
desc = Description.parse_xml(xml_text)
|
83
77
|
expected_xml = '<description xml:lang="en-us" descriptionType="Abstract"><br/> <br/> abstract <br></br> full <br /> of <br> </br>s</description>'
|
84
78
|
expect(desc.save_to_xml).to be_xml(expected_xml)
|
85
79
|
|
@@ -77,8 +77,7 @@ module Datacite
|
|
77
77
|
<geoLocationBox>41.090 -71.032 42.893 -68.211</geoLocationBox>
|
78
78
|
<geoLocationPlace>Atlantic Ocean</geoLocationPlace>
|
79
79
|
</geoLocation>'
|
80
|
-
|
81
|
-
loc = GeoLocation.load_from_xml(xml)
|
80
|
+
loc = GeoLocation.parse_xml(xml_text)
|
82
81
|
expect(loc.point).to eq(GeoLocationPoint.new(31.233, -67.302))
|
83
82
|
expect(loc.box).to eq(GeoLocationBox.new(41.09, -71.032, 42.893, -68.211))
|
84
83
|
expect(loc.place).to eq('Atlantic Ocean')
|
@@ -90,8 +89,7 @@ module Datacite
|
|
90
89
|
Atlantic Ocean
|
91
90
|
</geoLocationPlace>
|
92
91
|
</geoLocation>'
|
93
|
-
|
94
|
-
loc = GeoLocation.load_from_xml(xml)
|
92
|
+
loc = GeoLocation.parse_xml(xml_text)
|
95
93
|
expect(loc.place).to eq('Atlantic Ocean')
|
96
94
|
end
|
97
95
|
end
|
@@ -55,8 +55,7 @@ module Datacite
|
|
55
55
|
describe '#load_from_xml' do
|
56
56
|
it 'parses XML' do
|
57
57
|
xml_text = "<identifier identifierType='DOI'>10.14749/1407399498</identifier>"
|
58
|
-
|
59
|
-
id = Identifier.load_from_xml(xml)
|
58
|
+
id = Identifier.parse_xml(xml_text)
|
60
59
|
expect(id.identifier_type).to eq('DOI')
|
61
60
|
expect(id.value).to eq('10.14749/1407399498')
|
62
61
|
end
|
@@ -69,8 +69,7 @@ module Datacite
|
|
69
69
|
describe '#load_from_xml' do
|
70
70
|
it 'parses XML' do
|
71
71
|
xml_text = '<nameIdentifier schemeURI="http://orcid.org/" nameIdentifierScheme="ORCID">0000-0003-1632-8708</nameIdentifier>'
|
72
|
-
|
73
|
-
id = NameIdentifier.load_from_xml(xml)
|
72
|
+
id = NameIdentifier.parse_xml(xml_text)
|
74
73
|
expect(id.scheme).to eq('ORCID')
|
75
74
|
expect(id.scheme_uri).to eq(URI('http://orcid.org/'))
|
76
75
|
expect(id.value).to eq('0000-0003-1632-8708')
|
@@ -120,8 +120,7 @@ module Datacite
|
|
120
120
|
describe '#load_from_xml' do
|
121
121
|
it 'parses XML' do
|
122
122
|
xml_text = '<relatedIdentifier relatedIdentifierType="URL" relationType="HasMetadata" relatedMetadataScheme="citeproc+json" schemeType="Turtle" 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>'
|
123
|
-
|
124
|
-
id = RelatedIdentifier.load_from_xml(xml)
|
123
|
+
id = RelatedIdentifier.parse_xml(xml_text)
|
125
124
|
|
126
125
|
expected_id_type = RelatedIdentifierType::URL
|
127
126
|
expected_rel_type = RelationType::HAS_METADATA
|
@@ -717,8 +717,7 @@ module Datacite
|
|
717
717
|
|
718
718
|
it 'round-trips' do
|
719
719
|
xml_text = File.read('spec/data/resource.xml')
|
720
|
-
|
721
|
-
resource = Resource.load_from_xml(xml)
|
720
|
+
resource = Resource.parse_xml(xml_text)
|
722
721
|
expect(resource.save_to_xml).to be_xml(xml_text)
|
723
722
|
end
|
724
723
|
end
|
@@ -50,8 +50,7 @@ module Datacite
|
|
50
50
|
describe '#load_from_xml' do
|
51
51
|
it 'parses XML' do
|
52
52
|
xml_text = '<resourceType resourceTypeGeneral="Software">XML</resourceType>'
|
53
|
-
|
54
|
-
rt = ResourceType.load_from_xml(xml)
|
53
|
+
rt = ResourceType.parse_xml(xml_text)
|
55
54
|
expect(rt.resource_type_general).to eq(ResourceTypeGeneral::SOFTWARE)
|
56
55
|
expect(rt.value).to eq('XML')
|
57
56
|
end
|
@@ -51,8 +51,7 @@ module Datacite
|
|
51
51
|
describe '#load_from_xml' do
|
52
52
|
it 'reads XML' do
|
53
53
|
xml_text = '<rights rightsURI="http://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0 Universal</rights>'
|
54
|
-
|
55
|
-
rights = Rights.load_from_xml(xml)
|
54
|
+
rights = Rights.parse_xml(xml_text)
|
56
55
|
expect(rights.value).to eq('CC0 1.0 Universal')
|
57
56
|
expect(rights.uri).to eq(URI('http://creativecommons.org/publicdomain/zero/1.0/'))
|
58
57
|
end
|
@@ -60,8 +59,7 @@ module Datacite
|
|
60
59
|
xml_text = '<rights>
|
61
60
|
CC0 1.0 Universal
|
62
61
|
</rights>'
|
63
|
-
|
64
|
-
rights = Rights.load_from_xml(xml)
|
62
|
+
rights = Rights.parse_xml(xml_text)
|
65
63
|
expect(rights.value).to eq('CC0 1.0 Universal')
|
66
64
|
end
|
67
65
|
end
|
@@ -63,8 +63,7 @@ module Datacite
|
|
63
63
|
describe '#load_from_xml' do
|
64
64
|
it 'parses XML' do
|
65
65
|
xml_text = '<subject xml:lang="en-us" schemeURI="http://id.loc.gov/authorities/subjects" subjectScheme="LCSH">Mammals--Embryology</subject>'
|
66
|
-
|
67
|
-
subject = Subject.load_from_xml(xml)
|
66
|
+
subject = Subject.parse_xml(xml_text)
|
68
67
|
|
69
68
|
value = 'Mammals--Embryology'
|
70
69
|
lang = 'en-us'
|
@@ -79,8 +78,7 @@ module Datacite
|
|
79
78
|
|
80
79
|
it 'treats missing language as en' do
|
81
80
|
xml_text = '<subject schemeURI="http://id.loc.gov/authorities/subjects" subjectScheme="LCSH">Mammals--Embryology</subject>'
|
82
|
-
|
83
|
-
subject = Subject.load_from_xml(xml)
|
81
|
+
subject = Subject.parse_xml(xml_text)
|
84
82
|
expect(subject.language).to eq('en')
|
85
83
|
end
|
86
84
|
end
|
@@ -68,8 +68,7 @@ module Datacite
|
|
68
68
|
describe '#load_from_xml' do
|
69
69
|
it 'parses XML' do
|
70
70
|
xml_text = '<title xml:lang="en-emodeng" titleType="Subtitle">Together with an Appendix of the Same, Containing an Answer to Some Objections, Made by Severall Persons against That Hypothesis</title>'
|
71
|
-
|
72
|
-
title = Title.load_from_xml(xml)
|
71
|
+
title = Title.parse_xml(xml_text)
|
73
72
|
|
74
73
|
expected_lang = 'en-emodeng'
|
75
74
|
expected_type = TitleType::SUBTITLE
|
@@ -82,8 +81,7 @@ module Datacite
|
|
82
81
|
|
83
82
|
it 'treats missing language as en' do
|
84
83
|
xml_text = '<title>Physical oceanography from BT during cruise U99XX00542B_1979</title>'
|
85
|
-
|
86
|
-
title = Title.load_from_xml(xml)
|
84
|
+
title = Title.parse_xml(xml_text)
|
87
85
|
expect(title.language).to eq('en')
|
88
86
|
end
|
89
87
|
|
@@ -91,8 +89,7 @@ module Datacite
|
|
91
89
|
xml_text = '<title>
|
92
90
|
Physical oceanography from BT during cruise U99XX00542B_1979
|
93
91
|
</title>'
|
94
|
-
|
95
|
-
title = Title.load_from_xml(xml)
|
92
|
+
title = Title.parse_xml(xml_text)
|
96
93
|
expect(title.value).to eq('Physical oceanography from BT during cruise U99XX00542B_1979')
|
97
94
|
end
|
98
95
|
end
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typesafe_enum
|
@@ -37,6 +37,9 @@ dependencies:
|
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0.3'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.3.2
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -44,6 +47,9 @@ dependencies:
|
|
44
47
|
- - "~>"
|
45
48
|
- !ruby/object:Gem::Version
|
46
49
|
version: '0.3'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.3.2
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
name: bundler
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|