datacite-mapping 0.2.5 → 0.3.0
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/.rubocop.yml +23 -11
- data/.ruby-version +1 -1
- data/CHANGES.md +5 -0
- data/Gemfile +2 -0
- data/LICENSE.md +1 -1
- data/README.md +2 -2
- data/Rakefile +5 -3
- data/datacite-mapping.gemspec +9 -7
- data/examples/reading.rb +1 -1
- data/examples/writing.rb +1 -0
- data/lib/datacite/mapping.rb +2 -0
- data/lib/datacite/mapping/alternate_identifier.rb +4 -2
- data/lib/datacite/mapping/contributor.rb +5 -3
- data/lib/datacite/mapping/creator.rb +6 -4
- data/lib/datacite/mapping/date.rb +5 -5
- data/lib/datacite/mapping/date_value.rb +4 -2
- data/lib/datacite/mapping/description.rb +5 -3
- data/lib/datacite/mapping/empty_filtering_nodes.rb +2 -0
- data/lib/datacite/mapping/funding_reference.rb +6 -4
- data/lib/datacite/mapping/geo_location.rb +2 -0
- data/lib/datacite/mapping/geo_location_box.rb +12 -10
- data/lib/datacite/mapping/geo_location_node.rb +9 -7
- data/lib/datacite/mapping/geo_location_point.rb +8 -6
- data/lib/datacite/mapping/geo_location_polygon.rb +3 -1
- data/lib/datacite/mapping/identifier.rb +9 -7
- data/lib/datacite/mapping/module_info.rb +5 -3
- data/lib/datacite/mapping/name_identifier.rb +4 -2
- data/lib/datacite/mapping/namespace_extensions.rb +2 -0
- data/lib/datacite/mapping/read_only_nodes.rb +5 -3
- data/lib/datacite/mapping/related_identifier.rb +5 -3
- data/lib/datacite/mapping/resource.rb +15 -13
- data/lib/datacite/mapping/resource_type.rb +3 -1
- data/lib/datacite/mapping/rights.rb +3 -1
- data/lib/datacite/mapping/subject.rb +5 -3
- data/lib/datacite/mapping/title.rb +5 -3
- data/spec/.rubocop.yml +3 -0
- data/spec/rspec_custom_matchers.rb +8 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/datacite/mapping/alternate_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/contributor_spec.rb +2 -0
- data/spec/unit/datacite/mapping/creator_spec.rb +2 -0
- data/spec/unit/datacite/mapping/date_spec.rb +2 -0
- data/spec/unit/datacite/mapping/date_value_spec.rb +2 -0
- data/spec/unit/datacite/mapping/description_spec.rb +2 -0
- data/spec/unit/datacite/mapping/funding_reference_spec.rb +3 -1
- data/spec/unit/datacite/mapping/geo_location_box_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_point_spec.rb +2 -0
- data/spec/unit/datacite/mapping/geo_location_polygon_spec.rb +22 -20
- data/spec/unit/datacite/mapping/geo_location_spec.rb +24 -22
- data/spec/unit/datacite/mapping/identifier_spec.rb +8 -6
- data/spec/unit/datacite/mapping/name_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/related_identifier_spec.rb +2 -0
- data/spec/unit/datacite/mapping/resource_spec.rb +22 -18
- data/spec/unit/datacite/mapping/rights_spec.rb +3 -1
- data/spec/unit/datacite/mapping/subject_spec.rb +2 -0
- data/spec/unit/datacite/mapping/title_spec.rb +2 -0
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c6c78e95b15168e1d50cca76a43313c568e96f
|
4
|
+
data.tar.gz: '08f1de9f06449584c9b4bab11139cd0e79882bf0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d2b532ba6cb94d49403bebcef4afb565c7baee59c6ae43725b74fdbd9f6a40dd08ac88e68c2e907db47bab444352dc7c7d52046a2944341ca3df386cf088def
|
7
|
+
data.tar.gz: c69fc51f41731b7fd77692cf70714e8072ebfc0d3f847a24ee345428a2c382a3f2f901c5483c1d0ac26f2b0108c8081f9f4814ee92fe935556f7c84a8019e211
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
# Disable compact style check for example.rb
|
2
|
-
Style/ClassAndModuleChildren:
|
3
|
-
Exclude:
|
4
|
-
- 'example.rb'
|
5
|
-
|
6
1
|
# Disable line-length check; it's too easy for the cure to be worse than the disease
|
7
2
|
Metrics/LineLength:
|
8
3
|
Enabled: False
|
@@ -11,18 +6,35 @@ Metrics/LineLength:
|
|
11
6
|
Style/Documentation:
|
12
7
|
Enabled: false
|
13
8
|
|
14
|
-
# Allow one line around class body (
|
15
|
-
|
9
|
+
# Allow one line around class body (Layout/EmptyLines will still disallow two or more)
|
10
|
+
Layout/EmptyLinesAroundClassBody:
|
16
11
|
Enabled: false
|
17
12
|
|
18
|
-
# Allow one line around module body (
|
19
|
-
|
13
|
+
# Allow one line around module body (Layout/EmptyLines will still disallow two or more)
|
14
|
+
Layout/EmptyLinesAroundModuleBody:
|
20
15
|
Enabled: false
|
21
16
|
|
22
|
-
# Allow one line around block body (
|
23
|
-
|
17
|
+
# Allow one line around block body (Layout/EmptyLines will still disallow two or more)
|
18
|
+
Layout/EmptyLinesAroundBlockBody:
|
24
19
|
Enabled: false
|
25
20
|
|
26
21
|
# Allow leading underscores for 'internal' accessors
|
27
22
|
Lint/UnderscorePrefixedVariableName:
|
28
23
|
Enabled: false
|
24
|
+
|
25
|
+
# Seriously?
|
26
|
+
Style/CommentedKeyword:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Use DateTime to preserve compatibility
|
30
|
+
Style/DateTime:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
# Disable some checks in sample code
|
34
|
+
Style/ClassAndModuleChildren:
|
35
|
+
Exclude:
|
36
|
+
- 'examples/*'
|
37
|
+
|
38
|
+
Style/MixinUsage:
|
39
|
+
Exclude:
|
40
|
+
- 'examples/*'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2018 The Regents of the University of California
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -46,8 +46,8 @@ abstract.value
|
|
46
46
|
# => "XML example of all DataCite Metadata Schema v4.0 properties."
|
47
47
|
```
|
48
48
|
|
49
|
-
Note that Datacite::Mapping uses the
|
50
|
-
as [ResourceTypeGeneral](http://www.rubydoc.info/github/CDLUC3/datacite-mapping/master/Datacite/Mapping/ResourceTypeGeneral)
|
49
|
+
Note that Datacite::Mapping uses the [TypesafeEnum](https://github.com/dmolesUC3/typesafe_enum) gem to represent controlled
|
50
|
+
vocabularies such as [ResourceTypeGeneral](http://www.rubydoc.info/github/CDLUC3/datacite-mapping/master/Datacite/Mapping/ResourceTypeGeneral)
|
51
51
|
and [DescriptionType](http://www.rubydoc.info/github/CDLUC3/datacite-mapping/master/Datacite/Mapping/DescriptionType).
|
52
52
|
|
53
53
|
### Writing
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# ------------------------------------------------------------
|
2
4
|
# RSpec
|
3
5
|
|
@@ -8,7 +10,7 @@ namespace :spec do
|
|
8
10
|
|
9
11
|
desc 'Run all unit tests'
|
10
12
|
RSpec::Core::RakeTask.new(:unit) do |task|
|
11
|
-
task.rspec_opts = %w
|
13
|
+
task.rspec_opts = %w[--color --format documentation --order default]
|
12
14
|
task.pattern = 'unit/**/*_spec.rb'
|
13
15
|
end
|
14
16
|
|
@@ -38,7 +40,7 @@ RuboCop::RakeTask.new
|
|
38
40
|
|
39
41
|
desc 'List TODOs (from spec/todo.rb)'
|
40
42
|
RSpec::Core::RakeTask.new(:todo) do |task|
|
41
|
-
task.rspec_opts = %w
|
43
|
+
task.rspec_opts = %w[--color --format documentation --order default]
|
42
44
|
task.pattern = 'todo.rb'
|
43
45
|
end
|
44
46
|
|
@@ -46,4 +48,4 @@ end
|
|
46
48
|
# Defaults
|
47
49
|
|
48
50
|
desc 'Run unit tests, check test coverage, run acceptance tests, check code style'
|
49
|
-
task default: [
|
51
|
+
task default: %i[coverage rubocop]
|
data/datacite-mapping.gemspec
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
|
5
7
|
require 'uri'
|
6
8
|
require 'datacite/mapping/module_info'
|
7
9
|
|
8
|
-
Gem::Specification.new do |spec|
|
10
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
9
11
|
spec.name = Datacite::Mapping::NAME
|
10
12
|
spec.version = Datacite::Mapping::VERSION
|
11
13
|
spec.authors = ['David Moles']
|
@@ -15,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
15
17
|
spec.license = 'MIT'
|
16
18
|
|
17
19
|
origin = `git config --get remote.origin.url`.chomp
|
18
|
-
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.
|
20
|
+
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[^\/]+}, 'http://\1\2'))
|
19
21
|
spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
|
20
22
|
|
21
23
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -29,12 +31,12 @@ Gem::Specification.new do |spec|
|
|
29
31
|
|
30
32
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
31
33
|
spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
|
34
|
+
spec.add_development_dependency 'github-markup', '~> 1.4'
|
32
35
|
spec.add_development_dependency 'rake', '~> 10.4'
|
36
|
+
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
33
37
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 0.52'
|
34
39
|
spec.add_development_dependency 'simplecov', '~> 0.9.2'
|
35
40
|
spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
|
36
|
-
spec.add_development_dependency '
|
37
|
-
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
38
|
-
spec.add_development_dependency 'github-markup', '~> 1.4'
|
39
|
-
spec.add_development_dependency 'yard', '~> 0.8'
|
41
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
40
42
|
end
|
data/examples/reading.rb
CHANGED
data/examples/writing.rb
CHANGED
data/lib/datacite/mapping.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -19,14 +21,14 @@ module Datacite
|
|
19
21
|
# Sets the type. Cannot be nil.
|
20
22
|
# @param val [String] the identifier type
|
21
23
|
def type=(val)
|
22
|
-
|
24
|
+
raise ArgumentError, 'No identifier type provided' unless val
|
23
25
|
@type = val
|
24
26
|
end
|
25
27
|
|
26
28
|
# Sets the value. Cannot be nil.
|
27
29
|
# @param val [String] the value
|
28
30
|
def value=(val)
|
29
|
-
|
31
|
+
raise ArgumentError, 'No identifier value provided' unless val
|
30
32
|
@value = val
|
31
33
|
end
|
32
34
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
require 'datacite/mapping/name_identifier'
|
3
5
|
|
@@ -92,13 +94,13 @@ module Datacite
|
|
92
94
|
end
|
93
95
|
|
94
96
|
def name=(value)
|
95
|
-
new_value = value
|
96
|
-
|
97
|
+
new_value = value&.strip
|
98
|
+
raise ArgumentError, 'Name cannot be empty or nil' unless new_value && !new_value.empty?
|
97
99
|
@name = new_value
|
98
100
|
end
|
99
101
|
|
100
102
|
def type=(value)
|
101
|
-
|
103
|
+
raise ArgumentError, 'Type cannot be nil' unless value
|
102
104
|
@type = value
|
103
105
|
end
|
104
106
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping'
|
2
4
|
require 'datacite/mapping/read_only_nodes'
|
3
5
|
require 'datacite/mapping/name_identifier'
|
@@ -23,18 +25,18 @@ module Datacite
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def name=(value)
|
26
|
-
new_value = value
|
27
|
-
|
28
|
+
new_value = value&.strip
|
29
|
+
raise ArgumentError, 'Name cannot be empty or nil' unless new_value && !new_value.empty?
|
28
30
|
@name = new_value
|
29
31
|
end
|
30
32
|
|
31
33
|
def given_name=(value)
|
32
|
-
new_value = value
|
34
|
+
new_value = value&.strip
|
33
35
|
@given_name = new_value
|
34
36
|
end
|
35
37
|
|
36
38
|
def family_name=(value)
|
37
|
-
new_value = value
|
39
|
+
new_value = value&.strip
|
38
40
|
@family_name = new_value
|
39
41
|
end
|
40
42
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
|
3
5
|
require 'datacite/mapping/date_value'
|
@@ -67,7 +69,7 @@ module Datacite
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def type=(val)
|
70
|
-
|
72
|
+
raise ArgumentError, 'Date type cannot be nil' unless val
|
71
73
|
@type = val
|
72
74
|
end
|
73
75
|
|
@@ -80,14 +82,14 @@ module Datacite
|
|
80
82
|
@range_start, @range_end = parts.map(&:strip).map { |part| DateValue.new(part) unless part == '' }
|
81
83
|
# puts "#{val} -> [#{range_start}, #{range_end}]"
|
82
84
|
else
|
83
|
-
|
85
|
+
raise ArgumentError, "Unable to parse date value #{val}"
|
84
86
|
end
|
85
87
|
@value = date_value ? date_value.to_s : "#{range_start}/#{range_end}"
|
86
88
|
end
|
87
89
|
|
88
90
|
def <=>(other)
|
89
91
|
return nil unless other.class == self.class
|
90
|
-
[
|
92
|
+
%i[date_value range_start range_end type].each do |v|
|
91
93
|
order = send(v) <=> other.send(v)
|
92
94
|
return order if order.nonzero?
|
93
95
|
end
|
@@ -102,8 +104,6 @@ module Datacite
|
|
102
104
|
@value
|
103
105
|
end
|
104
106
|
|
105
|
-
private
|
106
|
-
|
107
107
|
# @!attribute [rw] type
|
108
108
|
# @return [DateType] the type of date. Cannot be nil.
|
109
109
|
typesafe_enum_node :type, '@dateType', class: DateType
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -52,12 +54,12 @@ module Datacite
|
|
52
54
|
@nsec = datetime.to_time.nsec
|
53
55
|
@zone = datetime.zone
|
54
56
|
end
|
55
|
-
|
57
|
+
raise ArgumentError, "Unable to parse date value '#{val}'" unless @year
|
56
58
|
end
|
57
59
|
|
58
60
|
def <=>(other)
|
59
61
|
return nil unless other.class == self.class
|
60
|
-
[
|
62
|
+
%i[year month day hour minute sec nsec].each do |v|
|
61
63
|
order = send(v) <=> other.send(v)
|
62
64
|
return order if order.nonzero?
|
63
65
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -88,12 +90,12 @@ module Datacite
|
|
88
90
|
end
|
89
91
|
|
90
92
|
def language=(value)
|
91
|
-
@language = value
|
93
|
+
@language = value&.strip
|
92
94
|
end
|
93
95
|
|
94
96
|
def value=(v)
|
95
|
-
new_value = v
|
96
|
-
|
97
|
+
new_value = v&.strip
|
98
|
+
raise ArgumentError, 'Value cannot be empty or nil' unless new_value && !new_value.empty?
|
97
99
|
@value = new_value
|
98
100
|
end
|
99
101
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping_extensions'
|
2
4
|
|
3
5
|
module Datacite
|
@@ -28,12 +30,12 @@ module Datacite
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def value=(value)
|
31
|
-
|
33
|
+
raise ArgumentError, 'Value cannot be empty or nil' unless value && !value.empty?
|
32
34
|
@value = value
|
33
35
|
end
|
34
36
|
|
35
37
|
def type=(value)
|
36
|
-
|
38
|
+
raise ArgumentError, 'Type cannot be nil' unless value
|
37
39
|
@type = value
|
38
40
|
end
|
39
41
|
|
@@ -59,7 +61,7 @@ module Datacite
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def value=(value)
|
62
|
-
|
64
|
+
raise ArgumentError, 'Value cannot be empty or nil' unless value && !value.empty?
|
63
65
|
@value = value
|
64
66
|
end
|
65
67
|
|
@@ -93,7 +95,7 @@ module Datacite
|
|
93
95
|
end
|
94
96
|
|
95
97
|
def to_s
|
96
|
-
fields = [
|
98
|
+
fields = %i[name identifier award_number award_title].map { |f| "#{f}: #{send(f)}" }
|
97
99
|
"FundingReference { #{fields.join(', ')} }"
|
98
100
|
end
|
99
101
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'xml/mapping'
|
2
4
|
require 'datacite/mapping/geo_location_node'
|
3
5
|
|
@@ -53,31 +55,31 @@ module Datacite
|
|
53
55
|
when 4
|
54
56
|
init_from_array(args)
|
55
57
|
else
|
56
|
-
|
58
|
+
raise ArgumentError, "Can't construct GeoLocationBox from arguments: #{args}"
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
def south_latitude=(value)
|
61
|
-
|
62
|
-
|
63
|
+
raise ArgumentError, 'South latitude cannot be nil' unless value
|
64
|
+
raise ArgumentError, "#{value} is not a valid south latitude" unless value >= -90 && value <= 90
|
63
65
|
@south_latitude = value
|
64
66
|
end
|
65
67
|
|
66
68
|
def west_longitude=(value)
|
67
|
-
|
68
|
-
|
69
|
+
raise ArgumentError, 'West longitude cannot be nil' unless value
|
70
|
+
raise ArgumentError, "#{value} is not a valid west longitude" unless value >= -180 && value <= 180
|
69
71
|
@west_longitude = value
|
70
72
|
end
|
71
73
|
|
72
74
|
def north_latitude=(value)
|
73
|
-
|
74
|
-
|
75
|
+
raise ArgumentError, 'North latitude cannot be nil' unless value
|
76
|
+
raise ArgumentError, "#{value} is not a valid north latitude" unless value >= -90 && value <= 90
|
75
77
|
@north_latitude = value
|
76
78
|
end
|
77
79
|
|
78
80
|
def east_longitude=(value)
|
79
|
-
|
80
|
-
|
81
|
+
raise ArgumentError, 'East longitude cannot be nil' unless value
|
82
|
+
raise ArgumentError, "#{value} is not a valid east longitude" unless value >= -180 && value <= 180
|
81
83
|
@east_longitude = value
|
82
84
|
end
|
83
85
|
|
@@ -94,7 +96,7 @@ module Datacite
|
|
94
96
|
# {GeoLocationBox}
|
95
97
|
def <=>(other)
|
96
98
|
return nil unless other.class == self.class
|
97
|
-
[
|
99
|
+
%i[south_latitude west_longitude north_latitude east_longitude].each do |c|
|
98
100
|
order = send(c) <=> other.send(c)
|
99
101
|
return order if order.nonzero?
|
100
102
|
end
|