datacite-mapping 0.1.7 → 0.1.9
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/CHANGES.md +9 -1
- data/lib/datacite/mapping/identifier.rb +11 -1
- data/lib/datacite/mapping/module_info.rb +1 -1
- data/lib/datacite/mapping/resource.rb +37 -0
- data/spec/unit/datacite/mapping/identifier_spec.rb +44 -0
- data/spec/unit/datacite/mapping/resource_spec.rb +54 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da1834970ac385ee240fbba08999da8c893b193f
|
4
|
+
data.tar.gz: 39da8961ce303ecb524b558fb497d47ee47b164f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7944af00561ea278f711f9aec4247f07fb69777e110fa4abe2f83b949e7dde2482b7acf3faa548603cd7f960b287433c8e879ddf03e001fd2a3b5e1e99196b7
|
7
|
+
data.tar.gz: 5232bb98d5f5447d04e007b912686e4bd9e4de547bc450b22b576bb47aa58cccf3ba6c64114fb91d22c5a695495cf11eff22bec1d169b063797aae812b8c19ce
|
data/CHANGES.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
## 0.1.
|
1
|
+
## 0.1.9 (19 April 2016)
|
2
|
+
|
3
|
+
- Added convenience methods to directly access creator names and affiliations
|
4
|
+
- Added convenience methods to directly access funder attributes
|
5
|
+
|
6
|
+
## 0.1.8 (7 April 2016)
|
7
|
+
|
8
|
+
- Add convenience method `Identifier.from_doi()` to parse DOI strings in various formats (`doi:`,
|
9
|
+
`http://dx.doi.org/`, etc.)
|
2
10
|
|
3
11
|
## 0.1.7 (28 March 2016)
|
4
12
|
|
@@ -2,6 +2,8 @@ require 'xml/mapping'
|
|
2
2
|
|
3
3
|
module Datacite
|
4
4
|
module Mapping
|
5
|
+
DOI_PATTERN = %r{10\..+/.+}
|
6
|
+
|
5
7
|
# The persistent identifier that identifies the resource.
|
6
8
|
#
|
7
9
|
# @!attribute [r] identifier_type
|
@@ -20,7 +22,7 @@ module Datacite
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def value=(v)
|
23
|
-
fail ArgumentError, "Identifier value '#{v}' is not a valid DOI" unless v.match(
|
25
|
+
fail ArgumentError, "Identifier value '#{v}' is not a valid DOI" unless v.match(DOI_PATTERN)
|
24
26
|
@value = v
|
25
27
|
end
|
26
28
|
|
@@ -32,6 +34,14 @@ module Datacite
|
|
32
34
|
@identifier_type = v
|
33
35
|
end
|
34
36
|
|
37
|
+
# Converts a string DOI value to an `Identifier`.
|
38
|
+
# @param doi_string [String]
|
39
|
+
def self.from_doi(doi_string)
|
40
|
+
match = doi_string.match(DOI_PATTERN)
|
41
|
+
fail ArgumentError, "'#{doi_string}' does not appear to contain a valid DOI" unless match
|
42
|
+
Identifier.new(value: match[0])
|
43
|
+
end
|
44
|
+
|
35
45
|
text_node :identifier_type, '@identifierType'
|
36
46
|
text_node :value, 'text()'
|
37
47
|
end
|
@@ -175,6 +175,43 @@ module Datacite
|
|
175
175
|
# @return [Array<GeoLocations>] spatial region or named place where the data was gathered or about which the data is focused.
|
176
176
|
array_node :geo_locations, 'geoLocations', 'geoLocation', class: GeoLocation, default_value: []
|
177
177
|
|
178
|
+
# Convenience method to get the creators' names.
|
179
|
+
# @return [[Array[String]] An array of the creators' names.
|
180
|
+
def creator_names
|
181
|
+
creators.map(&:name)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Convenience method to get the creators' affiliations. (Bear in mind that each creator
|
185
|
+
# can have multiple affiliations.)
|
186
|
+
# @return [Array[Array[String]]] An array containing each creator's array of affiliations.
|
187
|
+
def creator_affiliations
|
188
|
+
creators.map(&:affiliations)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Convenience method to get the funding contributor.
|
192
|
+
# @return [Contributor, nil] the contributor of type FUNDER, if any.
|
193
|
+
def funder_contrib
|
194
|
+
@funder_contrib ||= contributors.find { |c| c.type == ContributorType::FUNDER }
|
195
|
+
end
|
196
|
+
|
197
|
+
# Convenience method to get the name of the funding contributor.
|
198
|
+
# @return [String, nil] the name of the funding contributor, if any.
|
199
|
+
def funder_name
|
200
|
+
funder_contrib.name if funder_contrib
|
201
|
+
end
|
202
|
+
|
203
|
+
# Convenience method to get the funding contributor identifier.
|
204
|
+
# @return [NameIdentifier, nil] the identifier of the funding contributor, if any.
|
205
|
+
def funder_id
|
206
|
+
funder_contrib.identifier if funder_contrib
|
207
|
+
end
|
208
|
+
|
209
|
+
# Convenience method to get the funding contributor identifier as a string.
|
210
|
+
# @return [String, nil] the string value of the funding contributor's identifier, if any.
|
211
|
+
def funder_id_value
|
212
|
+
funder_id.value if funder_id
|
213
|
+
end
|
214
|
+
|
178
215
|
end
|
179
216
|
end
|
180
217
|
end
|
@@ -30,6 +30,50 @@ module Datacite
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
describe '#from_doi' do
|
34
|
+
it 'creates an identifier from a doi: string' do
|
35
|
+
doi_value = '10.1594/WDCC/CCSRNIES_SRES_B2'
|
36
|
+
doi_string = "doi:#{doi_value}"
|
37
|
+
id = Identifier.from_doi(doi_string)
|
38
|
+
expect(id).to be_an(Identifier)
|
39
|
+
expect(id.value).to eq(doi_value)
|
40
|
+
expect(id.identifier_type).to eq('DOI')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'creates an identifier from a plain DOI value' do
|
44
|
+
doi_value = '10.1594/WDCC/CCSRNIES_SRES_B2'
|
45
|
+
id = Identifier.from_doi(doi_value)
|
46
|
+
expect(id).to be_an(Identifier)
|
47
|
+
expect(id.value).to eq(doi_value)
|
48
|
+
expect(id.identifier_type).to eq('DOI')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'creates an identifier from a DOI in URL format' do
|
52
|
+
doi_value = '10.1594/WDCC/CCSRNIES_SRES_B2'
|
53
|
+
doi_string = "http://dx.doi.org/#{doi_value}"
|
54
|
+
id = Identifier.from_doi(doi_string)
|
55
|
+
expect(id).to be_an(Identifier)
|
56
|
+
expect(id.value).to eq(doi_value)
|
57
|
+
expect(id.identifier_type).to eq('DOI')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'raises ArgumentError if it is passed a bad DOI' do
|
61
|
+
bad_dois = %w(
|
62
|
+
20.14749/1407399495
|
63
|
+
11.14749/1407399495
|
64
|
+
10./1407399495
|
65
|
+
10.14749\1407399495
|
66
|
+
10.14749/
|
67
|
+
)
|
68
|
+
bad_dois.each do |doi|
|
69
|
+
expect { Identifier.from_doi(doi) }.to raise_error do |e|
|
70
|
+
expect(e).to be_an(ArgumentError)
|
71
|
+
expect(e.message).to include(doi)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
33
77
|
describe '#value=' do
|
34
78
|
it 'sets the value' do
|
35
79
|
id = Identifier.allocate
|
@@ -770,6 +770,60 @@ module Datacite
|
|
770
770
|
expect(resource.save_to_xml).to be_xml(xml_text)
|
771
771
|
end
|
772
772
|
end
|
773
|
+
|
774
|
+
describe 'convenience accessors' do
|
775
|
+
|
776
|
+
before :each do
|
777
|
+
xml_text = File.read('spec/data/resource.xml')
|
778
|
+
@resource = Resource.parse_xml(xml_text)
|
779
|
+
|
780
|
+
@funder = Contributor.new(
|
781
|
+
name: 'The Ministry of Magic',
|
782
|
+
identifier: NameIdentifier.new(
|
783
|
+
scheme: 'IATI',
|
784
|
+
scheme_uri: URI('http://iatistandard.org/201/codelists/OrganisationIdentifier/'),
|
785
|
+
value: 'GR-9¾'
|
786
|
+
),
|
787
|
+
type: ContributorType::FUNDER)
|
788
|
+
@resource.contributors << @funder
|
789
|
+
end
|
790
|
+
|
791
|
+
describe 'creator_names' do
|
792
|
+
it 'extracts the creator names' do
|
793
|
+
expect(@resource.creator_names).to eq(['Miller, Elizabeth'])
|
794
|
+
end
|
795
|
+
end
|
796
|
+
|
797
|
+
describe 'creator_affiliations' do
|
798
|
+
it 'extracts the creator affiliations' do
|
799
|
+
expect(@resource.creator_affiliations).to eq([['DataCite']])
|
800
|
+
end
|
801
|
+
end
|
802
|
+
|
803
|
+
describe 'funder_contrib' do
|
804
|
+
it 'extracts the funder contrib' do
|
805
|
+
expect(@resource.funder_contrib).to eq(@funder)
|
806
|
+
end
|
807
|
+
end
|
808
|
+
|
809
|
+
describe 'funder_name' do
|
810
|
+
it 'extracts the funder name' do
|
811
|
+
expect(@resource.funder_name).to eq(@funder.name)
|
812
|
+
end
|
813
|
+
end
|
814
|
+
|
815
|
+
describe 'funder_id' do
|
816
|
+
it 'extracts the funder id' do
|
817
|
+
expect(@resource.funder_id).to eq(@funder.identifier)
|
818
|
+
end
|
819
|
+
end
|
820
|
+
|
821
|
+
describe 'funder_id_value' do
|
822
|
+
it 'extracts the funder id value' do
|
823
|
+
expect(@resource.funder_id_value).to eq(@funder.identifier.value)
|
824
|
+
end
|
825
|
+
end
|
826
|
+
end
|
773
827
|
end
|
774
828
|
end
|
775
829
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typesafe_enum
|