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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdca4b9e61f6a7f61405cbfde5488540ba71afed
4
- data.tar.gz: fd61a9ad1a4993765d6cb5eec62dd5767d2efe72
3
+ metadata.gz: 57920b6deb33af54ffc30bbce3cf2943f069b74d
4
+ data.tar.gz: 7864e0a91b9034cbb949df41b374c7700294c37d
5
5
  SHA512:
6
- metadata.gz: ab8a01cf469aae1ce0cdc3b846bf0d17e30a481d567cdd084cf170af38d337c155a9d16574d972ea31e87e63d6b2b6795b0d79aba1f77847859dbf1980c10b15
7
- data.tar.gz: 753a1634b39d52e98fe2c04983da1e5fc7a622c7f47048af740faba7e58c0a54f3912f0b52dd1864a52c6bbf955d61b17c87201f979115e70f032aec4d91ef0b
6
+ metadata.gz: bfc67fba2953a659de6c9d6068fa242896fb3c35c32b140db9a56aeadc89ee6e13d218c76aac1636dcf4c1edaad09e006eecfcb4892a8b14a53d5e1320aeee18
7
+ data.tar.gz: 0a42d5ac00ed8af6307a5fc4dc97def2dd5ec086fe3cd1bd22a2797abb586c94188bbd34cd59ee4f45ef94c61362397bf05bb243a2cc4b1d14cd66b1b8f3e51f
data/.gitignore CHANGED
@@ -15,9 +15,9 @@
15
15
  *.a
16
16
  mkmf.log
17
17
 
18
- # Database
18
+ # Gem
19
19
 
20
- db/*.sqlite3
20
+ datacite*gem
21
21
 
22
22
  # Logs
23
23
 
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
- xml_text = File.read('resource.xml')
19
- resource = Resource.load_from_xml(xml.root)
20
- creators = resource.creators
21
- citation = ''
22
- citation << creators.map(&:name).join('; ')
23
- citation << ' '
24
- citation << "(#{resource.publication_year})"
25
- citation << ': '
26
- title = resource.titles[0].value
27
- citation << title
28
- citation << (title.end_with?('.') ? ' ' : '. ')
29
- citation << resource.publisher
30
-
31
- puts("Citation: #{citation}")
32
-
33
- abstract = resource.descriptions.find { |d| d.type = DescriptionType::ABSTRACT }
34
- puts("Abstract: #{abstract.value}")
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
- xml = resource.save_to_xml
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:
@@ -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 'URI'
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
- xml = REXML::Document.new(xml_text)
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
@@ -43,7 +43,4 @@ resource = Resource.new(
43
43
  ]
44
44
  )
45
45
 
46
- xml = resource.save_to_xml
47
- formatter = REXML::Formatters::Pretty.new
48
- formatter.compact = true
49
- formatter.write(xml, $stdout)
46
+ puts resource.write_xml
@@ -4,7 +4,7 @@ module Datacite
4
4
  NAME = 'datacite-mapping'
5
5
 
6
6
  # The version of this gem
7
- VERSION = '0.1.0'
7
+ VERSION = '0.1.1'
8
8
 
9
9
  # The copyright notice for this gem
10
10
  COPYRIGHT = 'Copyright (c) 2015 The Regents of the University of California'
@@ -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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
  &lt;p&gt;This is HTML text&lt;/p&gt;&lt;p&gt;&lt;small&gt;despite the advice in the standard&lt;/small&gt;&lt;/p&gt;
26
25
  </description>'
27
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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 &lt;br/&gt;s
46
43
  </description>'
47
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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/> &lt;br/&gt; abstract <br></br> full <br /> of <br> </br>s</description>'
81
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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
- xml = REXML::Document.new(xml_text).root
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.0
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 00:00:00.000000000 Z
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