datacite-mapping 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +42 -0
  3. data/.rubocop.yml +28 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +2 -0
  6. data/.yardopts +2 -0
  7. data/CHANGES.md +3 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE.md +22 -0
  10. data/README.md +168 -0
  11. data/Rakefile +49 -0
  12. data/datacite-mapping.gemspec +37 -0
  13. data/examples/reading.rb +75 -0
  14. data/examples/writing.rb +49 -0
  15. data/lib/datacite/mapping.rb +36 -0
  16. data/lib/datacite/mapping/alternate_identifier.rb +45 -0
  17. data/lib/datacite/mapping/contributor.rb +125 -0
  18. data/lib/datacite/mapping/creator.rb +48 -0
  19. data/lib/datacite/mapping/date.rb +153 -0
  20. data/lib/datacite/mapping/description.rb +121 -0
  21. data/lib/datacite/mapping/geo_location.rb +49 -0
  22. data/lib/datacite/mapping/geo_location_box.rb +137 -0
  23. data/lib/datacite/mapping/geo_location_point.rb +102 -0
  24. data/lib/datacite/mapping/identifier.rb +45 -0
  25. data/lib/datacite/mapping/module_info.rb +12 -0
  26. data/lib/datacite/mapping/name_identifier.rb +48 -0
  27. data/lib/datacite/mapping/related_identifier.rb +209 -0
  28. data/lib/datacite/mapping/resource.rb +201 -0
  29. data/lib/datacite/mapping/resource_type.rb +83 -0
  30. data/lib/datacite/mapping/rights.rb +36 -0
  31. data/lib/datacite/mapping/subject.rb +55 -0
  32. data/lib/datacite/mapping/title.rb +69 -0
  33. data/spec/.rubocop.yml +7 -0
  34. data/spec/data/resource.xml +61 -0
  35. data/spec/rspec_custom_matchers.rb +69 -0
  36. data/spec/spec_helper.rb +31 -0
  37. data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +60 -0
  38. data/spec/unit/datacite/mapping/contributor_spec.rb +129 -0
  39. data/spec/unit/datacite/mapping/creator_spec.rb +125 -0
  40. data/spec/unit/datacite/mapping/date_spec.rb +246 -0
  41. data/spec/unit/datacite/mapping/description_spec.rb +89 -0
  42. data/spec/unit/datacite/mapping/geo_location_box_spec.rb +241 -0
  43. data/spec/unit/datacite/mapping/geo_location_point_spec.rb +148 -0
  44. data/spec/unit/datacite/mapping/geo_location_spec.rb +116 -0
  45. data/spec/unit/datacite/mapping/identifier_spec.rb +75 -0
  46. data/spec/unit/datacite/mapping/name_identifier_spec.rb +89 -0
  47. data/spec/unit/datacite/mapping/related_identifier_spec.rb +157 -0
  48. data/spec/unit/datacite/mapping/resource_spec.rb +727 -0
  49. data/spec/unit/datacite/mapping/resource_type_spec.rb +69 -0
  50. data/spec/unit/datacite/mapping/rights_spec.rb +78 -0
  51. data/spec/unit/datacite/mapping/subject_spec.rb +108 -0
  52. data/spec/unit/datacite/mapping/title_spec.rb +113 -0
  53. metadata +262 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdca4b9e61f6a7f61405cbfde5488540ba71afed
4
+ data.tar.gz: fd61a9ad1a4993765d6cb5eec62dd5767d2efe72
5
+ SHA512:
6
+ metadata.gz: ab8a01cf469aae1ce0cdc3b846bf0d17e30a481d567cdd084cf170af38d337c155a9d16574d972ea31e87e63d6b2b6795b0d79aba1f77847859dbf1980c10b15
7
+ data.tar.gz: 753a1634b39d52e98fe2c04983da1e5fc7a622c7f47048af740faba7e58c0a54f3912f0b52dd1864a52c6bbf955d61b17c87201f979115e70f032aec4d91ef0b
@@ -0,0 +1,42 @@
1
+ # Ruby defaults
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+
18
+ # Database
19
+
20
+ db/*.sqlite3
21
+
22
+ # Logs
23
+
24
+ /log/
25
+
26
+ # IntellJ
27
+
28
+ *.iml
29
+ *.ipr
30
+ *.iws
31
+ *.ids
32
+ .rakeTasks
33
+
34
+ # Emacs
35
+
36
+ *~
37
+ \#*
38
+ .#*
39
+
40
+ # Mac OS
41
+
42
+ .DS_Store
@@ -0,0 +1,28 @@
1
+ # Disable compact style check for example.rb
2
+ Style/ClassAndModuleChildren:
3
+ Exclude:
4
+ - 'example.rb'
5
+
6
+ # Disable line-length check; it's too easy for the cure to be worse than the disease
7
+ Metrics/LineLength:
8
+ Enabled: False
9
+
10
+ # Disable problematic module documentation check (see https://github.com/bbatsov/rubocop/issues/947)
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ # Allow one line around class body (Style/EmptyLines will still disallow two or more)
15
+ Style/EmptyLinesAroundClassBody:
16
+ Enabled: false
17
+
18
+ # Allow one line around module body (Style/EmptyLines will still disallow two or more)
19
+ Style/EmptyLinesAroundModuleBody:
20
+ Enabled: false
21
+
22
+ # Allow one line around block body (Style/EmptyLines will still disallow two or more)
23
+ Style/EmptyLinesAroundBlockBody:
24
+ Enabled: false
25
+
26
+ # Allow leading underscores for 'internal' accessors
27
+ Lint/UnderscorePrefixedVariableName:
28
+ Enabled: false
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -0,0 +1,2 @@
1
+ language: ruby
2
+
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ --default-return ''
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (10 Dec 2015)
2
+
3
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 The Regents of the University of California
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,168 @@
1
+ # datacite-mapping
2
+
3
+ [![Build Status](https://travis-ci.org/CDLUC3/datacite-mapping.png?branch=master)](https://travis-ci.org/CDLUC3/datacite-mapping)
4
+ [![Code Climate](https://codeclimate.com/github/CDLUC3/datacite-mapping.png)](https://codeclimate.com/github/CDLUC3/datacite-mapping)
5
+ [![Inline docs](http://inch-ci.org/github/CDLUC3/datacite-mapping.png)](http://inch-ci.org/github/CDLUC3/datacite-mapping)
6
+ [![Gem Version](https://img.shields.io/gem/v/datacite-mapping.svg)](https://github.com/CDLUC3/datacite-mapping/releases)
7
+
8
+ A library for mapping [DataCite XML](http://schema.datacite.org/meta/kernel-3/) to Ruby objects.
9
+ Full API documentation on [RubyDoc.info](http://www.rubydoc.info/github/CDLUC3/datacite-mapping/master/frames).
10
+
11
+ ## Reading
12
+
13
+ ```ruby
14
+ require 'datacite/mapping'
15
+
16
+ include Datacite::Mapping
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}")
35
+ ```
36
+
37
+ Results:
38
+
39
+ ```
40
+ Citation: Schumann, Kai; Völker, David; Weinrebe, Wilhelm Reiber (2011):
41
+ Gridded results of swath bathymetric mapping of Disko Bay, Western
42
+ Greenland, 2007-2008. PANGAEA - Data Publisher for Earth & Environmental
43
+ Science
44
+
45
+ Abstract: A ship-based acoustic mapping campaign was conducted at the exit
46
+ of Ilulissat Ice Fjord and in the sedimentary basin of Disko Bay to the
47
+ west of the fjord mouth. Submarine landscape and sediment distribution
48
+ patterns are interpreted in terms of glaciomarine facies types that are
49
+ related to variations in the past position of the glacier front. In
50
+ particular, asymmetric ridges that form a curved entity and a large sill at
51
+ the fjord mouth may represent moraines that depict at least two relatively
52
+ stable positions of the ice front in the Disko Bay and at the fjord mouth.
53
+ In this respect, Ilulissat Glacier shows prominent differences to the East
54
+ Greenland Kangerlussuaq Glacier which is comparable in present size and
55
+ present role for the ice discharge from the inland ice sheet. Two linear
56
+ clusters of pockmarks in the center of the sedimentary basin seem to be
57
+ linked to ongoing methane release due to dissociation of gas hydrates, a
58
+ process fueled by climate warming in the Arctic realm.
59
+ ```
60
+
61
+ ## Writing
62
+
63
+ ```ruby
64
+ require 'datacite/mapping'
65
+ include Datacite::Mapping
66
+
67
+ # Based on "Example for a simple dataset"
68
+ # http://schema.datacite.org/meta/kernel-3/example/datacite-example-dataset-v3.0.xml
69
+ resource = Resource.new(
70
+ identifier: Identifier.new(value: '10.5072/D3P26Q35R-Test'),
71
+ creators: [
72
+ Creator.new(name: 'Fosmire, Michael'),
73
+ Creator.new(name: 'Wertz, Ruth'),
74
+ Creator.new(name: 'Purzer, Senay')
75
+ ],
76
+ titles: [
77
+ Title.new(value: 'Critical Engineering Literacy Test (CELT)')
78
+ ],
79
+ publisher: 'Purdue University Research Repository (PURR)',
80
+ publication_year: 2013,
81
+ subjects: [
82
+ Subject.new(value: 'Assessment'),
83
+ Subject.new(value: 'Information Literacy'),
84
+ Subject.new(value: 'Engineering'),
85
+ Subject.new(value: 'Undergraduate Students'),
86
+ Subject.new(value: 'CELT'),
87
+ Subject.new(value: 'Purdue University')
88
+ ],
89
+ language: 'en',
90
+ resource_type: ResourceType.new(resource_type_general: ResourceTypeGeneral::DATASET, value: 'Dataset'),
91
+ version: '1',
92
+ descriptions: [
93
+ Description.new(
94
+ type: DescriptionType::ABSTRACT,
95
+ value: 'We developed an instrument, Critical Engineering Literacy Test
96
+ (CELT), which is a multiple choice instrument designed to
97
+ measure undergraduate students’ scientific and information
98
+ literacy skills. It requires students to first read a
99
+ technical memo and, based on the memo’s arguments, answer
100
+ eight multiple choice and six open-ended response questions.
101
+ We collected data from 143 first-year engineering students and
102
+ conducted an item analysis. The KR-20 reliability of the
103
+ instrument was .39. Item difficulties ranged between .17 to
104
+ .83. The results indicate low reliability index but acceptable
105
+ levels of item difficulties and item discrimination indices.
106
+ Students were most challenged when answering items measuring
107
+ scientific and mathematical literacy (i.e., identifying
108
+ incorrect information).'
109
+ )
110
+ ]
111
+ )
112
+
113
+ xml = resource.save_to_xml
114
+ formatter = REXML::Formatters::Pretty.new
115
+ formatter.compact = true
116
+ formatter.write(xml, $stdout)
117
+ ```
118
+
119
+ Results:
120
+
121
+ ```xml
122
+ <resource xmlns='http://datacite.org/schema/kernel-3' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd'>
123
+ <identifier identifierType='DOI'>10.5072/D3P26Q35R-Test</identifier>
124
+ <creators>
125
+ <creator>
126
+ <creatorName>Fosmire, Michael</creatorName>
127
+ </creator>
128
+ <creator>
129
+ <creatorName>Wertz, Ruth</creatorName>
130
+ </creator>
131
+ <creator>
132
+ <creatorName>Purzer, Senay</creatorName>
133
+ </creator>
134
+ </creators>
135
+ <titles>
136
+ <title xml:lang='en'>Critical Engineering Literacy Test (CELT)</title>
137
+ </titles>
138
+ <publisher>Purdue University Research Repository (PURR)</publisher>
139
+ <publicationYear>2013</publicationYear>
140
+ <subjects>
141
+ <subject xml:lang='en'>Assessment</subject>
142
+ <subject xml:lang='en'>Information Literacy</subject>
143
+ <subject xml:lang='en'>Engineering</subject>
144
+ <subject xml:lang='en'>Undergraduate Students</subject>
145
+ <subject xml:lang='en'>CELT</subject>
146
+ <subject xml:lang='en'>Purdue University</subject>
147
+ </subjects>
148
+ <language>en</language>
149
+ <resourceType resourceTypeGeneral='Dataset'>Dataset</resourceType>
150
+ <version>1</version>
151
+ <descriptions>
152
+ <description xml:lang='en' descriptionType='Abstract'>
153
+ We developed an instrument, Critical Engineering Literacy Test (CELT),
154
+ which is a multiple choice instrument designed to measure undergraduate
155
+ students’ scientific and information literacy skills. It requires students
156
+ to first read a technical memo and, based on the memo’s arguments, answer
157
+ eight multiple choice and six open-ended response questions. We collected
158
+ data from 143 first-year engineering students and conducted an item
159
+ analysis. The KR-20 reliability of the instrument was .39. Item
160
+ difficulties ranged between .17 to .83. The results indicate low
161
+ reliability index but acceptable levels of item difficulties and item
162
+ discrimination indices. Students were most challenged when answering items
163
+ measuring scientific and mathematical literacy (i.e., identifying
164
+ incorrect information).
165
+ </description>
166
+ </descriptions>
167
+ </resource>
168
+ ```
@@ -0,0 +1,49 @@
1
+ # ------------------------------------------------------------
2
+ # RSpec
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ namespace :spec do
8
+
9
+ desc 'Run all unit tests'
10
+ RSpec::Core::RakeTask.new(:unit) do |task|
11
+ task.rspec_opts = %w(--color --format documentation --order default)
12
+ task.pattern = 'unit/**/*_spec.rb'
13
+ end
14
+
15
+ task all: [:unit]
16
+ end
17
+
18
+ desc 'Run all tests'
19
+ task spec: 'spec:all'
20
+
21
+ # ------------------------------------------------------------
22
+ # Coverage
23
+
24
+ desc 'Run all unit tests with coverage'
25
+ task :coverage do
26
+ ENV['COVERAGE'] = 'true'
27
+ Rake::Task['spec:unit'].execute
28
+ end
29
+
30
+ # ------------------------------------------------------------
31
+ # RuboCop
32
+
33
+ require 'rubocop/rake_task'
34
+ RuboCop::RakeTask.new
35
+
36
+ # ------------------------------------------------------------
37
+ # TODOs
38
+
39
+ desc 'List TODOs (from spec/todo.rb)'
40
+ RSpec::Core::RakeTask.new(:todo) do |task|
41
+ task.rspec_opts = %w(--color --format documentation --order default)
42
+ task.pattern = 'todo.rb'
43
+ end
44
+
45
+ # ------------------------------------------------------------
46
+ # Defaults
47
+
48
+ desc 'Run unit tests, check test coverage, run acceptance tests, check code style'
49
+ task default: [:coverage, :rubocop]
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'URI'
6
+ require 'datacite/mapping/module_info'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = Datacite::Mapping::NAME
10
+ spec.version = Datacite::Mapping::VERSION
11
+ spec.authors = ['David Moles']
12
+ spec.email = ['david.moles@ucop.edu']
13
+ spec.summary = 'Parses and generates Datacite XML documents'
14
+ spec.description = 'A gem for working with the Datacite XML format'
15
+ spec.license = 'MIT'
16
+
17
+ origin_uri = URI(`git config --get remote.origin.url`.chomp)
18
+ spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.2'
27
+ spec.add_dependency 'xml-mapping_extensions', '~> 0.3'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.7'
30
+ spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
31
+ spec.add_development_dependency 'rake', '~> 10.4'
32
+ spec.add_development_dependency 'rspec', '~> 3.2'
33
+ spec.add_development_dependency 'simplecov', '~> 0.9.2'
34
+ spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
35
+ spec.add_development_dependency 'rubocop', '~> 0.32.1'
36
+ spec.add_development_dependency 'yard', '~> 0.8'
37
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: UTF-8
3
+
4
+ require 'datacite/mapping'
5
+ include Datacite::Mapping
6
+
7
+ xml_text = '<?xml version="1.0" encoding="UTF-8"?>
8
+ <resource xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd" xmlns="http://datacite.org/schema/kernel-3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
9
+ <identifier identifierType="DOI">10.5072/geoPointExample</identifier>
10
+ <creators>
11
+ <creator>
12
+ <creatorName>Schumann, Kai</creatorName>
13
+ </creator>
14
+ <creator>
15
+ <creatorName>Völker, David</creatorName>
16
+ </creator>
17
+ <creator>
18
+ <creatorName>Weinrebe, Wilhelm Reiber</creatorName>
19
+ </creator>
20
+ </creators>
21
+ <titles>
22
+ <title>Gridded results of swath bathymetric mapping of Disko Bay, Western Greenland, 2007-2008</title>
23
+ </titles>
24
+ <publisher>PANGAEA - Data Publisher for Earth &amp; Environmental Science</publisher>
25
+ <publicationYear>2011</publicationYear>
26
+ <subjects>
27
+ <subject subjectScheme="DDC">551 Geology, hydrology, meteorology</subject>
28
+ </subjects>
29
+ <contributors>
30
+ <contributor contributorType="HostingInstitution">
31
+ <contributorName>IFM-GEOMAR Leibniz-Institute of Marine Sciences, Kiel University</contributorName>
32
+ </contributor>
33
+ </contributors>
34
+ <language>en</language>
35
+ <resourceType resourceTypeGeneral="Dataset"/>
36
+ <relatedIdentifiers>
37
+ <relatedIdentifier relatedIdentifierType="DOI" relationType="Continues">10.5072/timeSeries</relatedIdentifier>
38
+ </relatedIdentifiers>
39
+ <sizes>
40
+ <size>4 datasets</size>
41
+ </sizes>
42
+ <formats>
43
+ <format>application/zip</format>
44
+ </formats>
45
+ <rightsList><rights rightsURI="http://creativecommons.org/licenses/by/3.0/deed">Creative Commons Attribution 3.0 Unported</rights></rightsList>
46
+ <descriptions>
47
+ <description descriptionType="Abstract">A ship-based acoustic mapping campaign was conducted at the exit of Ilulissat Ice Fjord and in the sedimentary basin of Disko Bay to the west of the fjord mouth. Submarine landscape and sediment distribution patterns are interpreted in terms of glaciomarine facies types that are related to variations in the past position of the glacier front. In particular, asymmetric ridges that form a curved entity and a large sill at the fjord mouth may represent moraines that depict at least two relatively stable positions of the ice front in the Disko Bay and at the fjord mouth. In this respect, Ilulissat Glacier shows prominent differences to the East Greenland Kangerlussuaq Glacier which is comparable in present size and present role for the ice discharge from the inland ice sheet. Two linear clusters of pockmarks in the center of the sedimentary basin seem to be linked to ongoing methane release due to dissociation of gas hydrates, a process fueled by climate warming in the Arctic realm.
48
+ </description>
49
+ </descriptions>
50
+ <geoLocations>
51
+ <geoLocation>
52
+ <geoLocationPoint>-52.000000 69.000000 </geoLocationPoint>
53
+ <geoLocationPlace>Disko Bay</geoLocationPlace>
54
+ </geoLocation>
55
+ </geoLocations>
56
+ </resource>'
57
+
58
+ xml = REXML::Document.new(xml_text)
59
+ resource = Resource.load_from_xml(xml.root)
60
+
61
+ creators = resource.creators
62
+ citation = ''
63
+ citation << creators.map(&:name).join('; ')
64
+ citation << ' '
65
+ citation << "(#{resource.publication_year})"
66
+ citation << ': '
67
+ title = resource.titles[0].value
68
+ citation << title
69
+ citation << (title.end_with?('.') ? ' ' : '. ')
70
+ citation << resource.publisher
71
+
72
+ puts("Citation: #{citation}")
73
+
74
+ abstract = resource.descriptions.find { |d| d.type = DescriptionType::ABSTRACT }
75
+ puts("Abstract: #{abstract.value}")