datacite-mapping 0.4.0 → 0.5.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 +6 -0
- data/.ruby-version +1 -1
- data/CHANGES.md +5 -1
- data/datacite-mapping.gemspec +5 -3
- data/lib/datacite/mapping/affiliation.rb +1 -1
- data/lib/datacite/mapping/contributor.rb +1 -1
- data/lib/datacite/mapping/contributor_name.rb +1 -1
- data/lib/datacite/mapping/creator_name.rb +1 -1
- data/lib/datacite/mapping/date.rb +8 -6
- data/lib/datacite/mapping/date_value.rb +2 -11
- data/lib/datacite/mapping/description.rb +1 -1
- data/lib/datacite/mapping/funding_reference.rb +2 -2
- data/lib/datacite/mapping/geo_location_box.rb +6 -6
- data/lib/datacite/mapping/geo_location_node.rb +2 -3
- data/lib/datacite/mapping/geo_location_point.rb +6 -4
- data/lib/datacite/mapping/geo_location_polygon.rb +1 -1
- data/lib/datacite/mapping/identifier.rb +1 -1
- data/lib/datacite/mapping/module_info.rb +2 -2
- data/lib/datacite/mapping/name_identifier.rb +1 -1
- data/lib/datacite/mapping/publisher.rb +1 -1
- data/lib/datacite/mapping/read_only_nodes.rb +3 -0
- data/lib/datacite/mapping/resource.rb +3 -3
- data/lib/datacite/mapping/subject.rb +1 -1
- data/lib/datacite/mapping/title.rb +1 -1
- data/spec/unit/datacite/mapping/date_value_spec.rb +1 -1
- data/spec/unit/datacite/mapping/resource_spec.rb +108 -109
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a6ecd59de223d63f3cbdba50679fd649e3b90b5faf54ac5c5d441cfc32c8a6f
|
4
|
+
data.tar.gz: ea434e0efa6850179bd6147a95e21ce0f682d6494d950bd7184dcb5eea929cdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2e1ffe1f08383143bea79f9dd4d48404e60ecde812e6c2b089fec7a4ea6ff385b4f6a0e95e1cfda9baee9c6f99a85790c17f7abd0b94b980c44a0e0bebc5464
|
7
|
+
data.tar.gz: 5ee1fecb57d8eb8a7ca6a94ea3c2ecc02cf7872896350328ab42a2f292b6f51e599c0c427d5b444daa189f6db645a4ee7bd585dd96989e4b557fa967c0810240
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.4
|
data/CHANGES.md
CHANGED
data/datacite-mapping.gemspec
CHANGED
@@ -16,9 +16,11 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
origin = `git config --get remote.origin.url`.chomp
|
19
|
-
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[
|
19
|
+
origin_uri = origin.start_with?('http') ? URI(origin) : URI(origin.gsub(%r{git@([^:]+)(.com|.org)[^/]+}, 'http://\1\2'))
|
20
20
|
spec.homepage = URI::HTTP.build(host: origin_uri.host, path: origin_uri.path.chomp('.git')).to_s
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 3.0.0'
|
23
|
+
|
22
24
|
spec.files = `git ls-files -z`.split("\x0")
|
23
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
26
|
|
@@ -28,10 +30,10 @@ Gem::Specification.new do |spec|
|
|
28
30
|
spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.7'
|
29
31
|
spec.add_dependency 'xml-mapping_extensions', '~> 0.4', '>= 0.4.7'
|
30
32
|
|
31
|
-
spec.add_development_dependency 'bundler', '
|
33
|
+
spec.add_development_dependency 'bundler', '>= 2.2.33'
|
32
34
|
spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
|
33
35
|
spec.add_development_dependency 'github-markup', '~> 1.4'
|
34
|
-
spec.add_development_dependency 'rake', '
|
36
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
35
37
|
spec.add_development_dependency 'redcarpet', '~> 3.3'
|
36
38
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
37
39
|
spec.add_development_dependency 'rubocop', '~> 0.52'
|
@@ -8,7 +8,7 @@ module Datacite
|
|
8
8
|
class Affiliation
|
9
9
|
include XML::Mapping
|
10
10
|
|
11
|
-
def initialize(identifier: nil, identifier_scheme: nil, scheme_uri: nil
|
11
|
+
def initialize(value:, identifier: nil, identifier_scheme: nil, scheme_uri: nil)
|
12
12
|
self.identifier = identifier
|
13
13
|
self.identifier_scheme = identifier_scheme
|
14
14
|
self.scheme_uri = scheme_uri
|
@@ -87,7 +87,7 @@ module Datacite
|
|
87
87
|
# @param identifier [NameIdentifier, nil] an identifier for the contributor. Optional.
|
88
88
|
# @param affiliations [Array<Affiliation>] the contributor's affiliations. Defaults to an empty list.
|
89
89
|
# @param type [ContributorType] the contributor type. Cannot be nil.
|
90
|
-
def initialize(name:, identifier: nil, affiliations: nil
|
90
|
+
def initialize(name:, type:, identifier: nil, affiliations: nil)
|
91
91
|
self.name = name
|
92
92
|
self.identifier = identifier
|
93
93
|
self.affiliations = affiliations || []
|
@@ -60,9 +60,7 @@ module Datacite
|
|
60
60
|
include Comparable
|
61
61
|
include XML::Mapping
|
62
62
|
|
63
|
-
attr_reader :date_value
|
64
|
-
attr_reader :range_start
|
65
|
-
attr_reader :range_end
|
63
|
+
attr_reader :date_value, :range_start, :range_end
|
66
64
|
|
67
65
|
# Initializes a new `Date`
|
68
66
|
#
|
@@ -80,12 +78,15 @@ module Datacite
|
|
80
78
|
@type = val
|
81
79
|
end
|
82
80
|
|
81
|
+
# rubocop:disable Metrics/MethodLength
|
82
|
+
|
83
83
|
def value=(val) # rubocop:disable Metrics/AbcSize
|
84
84
|
parts = val.to_s.split('/', -1) # negative limit so we don't drop trailing empty string
|
85
85
|
@date_value, @range_start, @range_end = nil
|
86
|
-
|
86
|
+
case parts.size
|
87
|
+
when 1
|
87
88
|
@date_value = DateValue.new(val)
|
88
|
-
|
89
|
+
when 2
|
89
90
|
@range_start, @range_end = parts.map(&:strip).map { |part| DateValue.new(part) unless part == '' }
|
90
91
|
# puts "#{val} -> [#{range_start}, #{range_end}]"
|
91
92
|
else
|
@@ -93,9 +94,10 @@ module Datacite
|
|
93
94
|
end
|
94
95
|
@value = date_value ? date_value.to_s : "#{range_start}/#{range_end}"
|
95
96
|
end
|
97
|
+
# rubocop:enable Metrics/MethodLength
|
96
98
|
|
97
99
|
def <=>(other)
|
98
|
-
return nil unless other.
|
100
|
+
return nil unless other.instance_of?(self.class)
|
99
101
|
|
100
102
|
%i[date_value range_start range_end type].each do |v|
|
101
103
|
order = send(v) <=> other.send(v)
|
@@ -25,16 +25,7 @@ module Datacite
|
|
25
25
|
class DateValue
|
26
26
|
include Comparable
|
27
27
|
|
28
|
-
attr_reader :year
|
29
|
-
attr_reader :month
|
30
|
-
attr_reader :day
|
31
|
-
attr_reader :hour
|
32
|
-
attr_reader :minute
|
33
|
-
attr_reader :sec
|
34
|
-
attr_reader :nsec
|
35
|
-
attr_reader :date
|
36
|
-
attr_reader :zone
|
37
|
-
attr_reader :iso_value
|
28
|
+
attr_reader :year, :month, :day, :hour, :minute, :sec, :nsec, :date, :zone, :iso_value
|
38
29
|
|
39
30
|
# Creates a new {DateValue}.
|
40
31
|
#
|
@@ -58,7 +49,7 @@ module Datacite
|
|
58
49
|
end
|
59
50
|
|
60
51
|
def <=>(other)
|
61
|
-
return nil unless other.
|
52
|
+
return nil unless other.instance_of?(self.class)
|
62
53
|
|
63
54
|
%i[year month day hour minute sec nsec].each do |v|
|
64
55
|
order = send(v) <=> other.send(v)
|
@@ -86,7 +86,7 @@ module Datacite
|
|
86
86
|
# @param type [DescriptionType] the description type.
|
87
87
|
# @param value [String] the description itself. See {Description} for notes on special
|
88
88
|
# handling of `<br/>` tags.
|
89
|
-
def initialize(
|
89
|
+
def initialize(type:, value:, language: nil)
|
90
90
|
self.language = language
|
91
91
|
self.type = type
|
92
92
|
self.value = value
|
@@ -27,7 +27,7 @@ module Datacite
|
|
27
27
|
|
28
28
|
# @param type [FunderIdentifierType] the identifier type. Cannot be nil.
|
29
29
|
# @param value [String] the identifier value. Cannot be nil.
|
30
|
-
def initialize(type:, scheme_uri: nil
|
30
|
+
def initialize(type:, value:, scheme_uri: nil)
|
31
31
|
self.type = type
|
32
32
|
self.scheme_uri = scheme_uri
|
33
33
|
self.value = value
|
@@ -65,7 +65,7 @@ module Datacite
|
|
65
65
|
class AwardNumber
|
66
66
|
include XML::Mapping
|
67
67
|
|
68
|
-
def initialize(uri: nil
|
68
|
+
def initialize(value:, uri: nil)
|
69
69
|
self.uri = uri
|
70
70
|
self.value = value
|
71
71
|
end
|
@@ -19,10 +19,7 @@ module Datacite
|
|
19
19
|
class GeoLocationBox
|
20
20
|
include Comparable
|
21
21
|
|
22
|
-
attr_reader :south_latitude
|
23
|
-
attr_reader :west_longitude
|
24
|
-
attr_reader :north_latitude
|
25
|
-
attr_reader :east_longitude
|
22
|
+
attr_reader :south_latitude, :west_longitude, :north_latitude, :east_longitude
|
26
23
|
|
27
24
|
# Initializes a new {GeoLocationBox}. The arguments can be provided
|
28
25
|
# either as a named-parameter hash, or as a list of four coordinates
|
@@ -51,7 +48,10 @@ module Datacite
|
|
51
48
|
def initialize(*args)
|
52
49
|
case args.length
|
53
50
|
when 1
|
54
|
-
|
51
|
+
raise ArgumentError, "Can't construct GeoLocationBox from arguments: #{args}" unless args[0].respond_to?(:keys)
|
52
|
+
|
53
|
+
init_from_hash(**args[0])
|
54
|
+
|
55
55
|
when 4
|
56
56
|
init_from_array(args)
|
57
57
|
else
|
@@ -99,7 +99,7 @@ module Datacite
|
|
99
99
|
# @return [Fixnum, nil] the sort order (-1, 0, or 1), or nil if `other` is not a
|
100
100
|
# {GeoLocationBox}
|
101
101
|
def <=>(other)
|
102
|
-
return nil unless other.
|
102
|
+
return nil unless other.instance_of?(self.class)
|
103
103
|
|
104
104
|
%i[south_latitude west_longitude north_latitude east_longitude].each do |c|
|
105
105
|
order = send(c) <=> other.send(c)
|
@@ -7,8 +7,7 @@ module Datacite
|
|
7
7
|
# Abstract superclass of GeoLocation parsing nodes
|
8
8
|
class GeoLocationNode < XML::Mapping::SingleAttributeNode
|
9
9
|
|
10
|
-
attr_reader :geom_class
|
11
|
-
attr_reader :coord_elements
|
10
|
+
attr_reader :geom_class, :coord_elements
|
12
11
|
|
13
12
|
def initialize(*args)
|
14
13
|
raise 'No geometry class provided' unless @geom_class
|
@@ -30,7 +29,7 @@ module Datacite
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def set_attr_value(xml, value)
|
33
|
-
raise "Invalid value: expected #{geom_class} instance, was #{value || 'nil'}" unless value
|
32
|
+
raise "Invalid value: expected #{geom_class} instance, was #{value || 'nil'}" unless value.is_a?(geom_class)
|
34
33
|
|
35
34
|
element = @path.first(xml, ensure_created: true)
|
36
35
|
|
@@ -15,8 +15,7 @@ module Datacite
|
|
15
15
|
class GeoLocationPoint
|
16
16
|
include Comparable
|
17
17
|
|
18
|
-
attr_reader :latitude
|
19
|
-
attr_reader :longitude
|
18
|
+
attr_reader :latitude, :longitude
|
20
19
|
|
21
20
|
# Initializes a new {GeoLocationPoint}. The arguments can be provided
|
22
21
|
# either as a named-parameter hash, or as a pair of coordinates in the
|
@@ -31,7 +30,10 @@ module Datacite
|
|
31
30
|
def initialize(*args)
|
32
31
|
case args.length
|
33
32
|
when 1
|
34
|
-
|
33
|
+
raise ArgumentError, "Can't construct GeoLocationPoint from arguments: #{args}" unless args[0].respond_to?(:keys)
|
34
|
+
|
35
|
+
init_from_hash(**args[0])
|
36
|
+
|
35
37
|
when 2
|
36
38
|
init_from_array(args)
|
37
39
|
else
|
@@ -65,7 +67,7 @@ module Datacite
|
|
65
67
|
# @return [Fixnum, nil] the sort order (-1, 0, or 1), or nil if `other` is not a
|
66
68
|
# {GeoLocationPoint}
|
67
69
|
def <=>(other)
|
68
|
-
return nil unless other.
|
70
|
+
return nil unless other.instance_of?(self.class)
|
69
71
|
|
70
72
|
%i[latitude longitude].each do |c|
|
71
73
|
order = send(c) <=> other.send(c)
|
@@ -6,9 +6,9 @@ module Datacite
|
|
6
6
|
NAME = 'datacite-mapping'
|
7
7
|
|
8
8
|
# The version of this gem
|
9
|
-
VERSION = '0.
|
9
|
+
VERSION = '0.5.0'
|
10
10
|
|
11
11
|
# The copyright notice for this gem
|
12
|
-
COPYRIGHT = 'Copyright (c)
|
12
|
+
COPYRIGHT = 'Copyright (c) 2022 The Regents of the University of California'
|
13
13
|
end
|
14
14
|
end
|
@@ -12,7 +12,7 @@ module Datacite
|
|
12
12
|
# @param scheme [Scheme] the name identifier scheme. Cannot be nil.
|
13
13
|
# @param scheme_uri [URI, nil] the URI of the identifier scheme. Optional.
|
14
14
|
# @param value [String] the identifier value. Cannot be nil.
|
15
|
-
def initialize(scheme:, scheme_uri: nil
|
15
|
+
def initialize(scheme:, value:, scheme_uri: nil)
|
16
16
|
self.scheme = scheme
|
17
17
|
self.scheme_uri = scheme_uri
|
18
18
|
self.value = value
|
@@ -12,7 +12,7 @@ module Datacite
|
|
12
12
|
# Initializes a new {Publisher}
|
13
13
|
# @param language [String, nil] an IETF BCP 47, ISO 639-1 language code identifying the language.
|
14
14
|
# @param value [String] name of the publisher
|
15
|
-
def initialize(language: nil
|
15
|
+
def initialize(value:, language: nil)
|
16
16
|
self.language = language
|
17
17
|
self.value = value
|
18
18
|
end
|
@@ -39,10 +39,13 @@ module Datacite
|
|
39
39
|
ReadOnlyNodes.warn(warning)
|
40
40
|
end
|
41
41
|
|
42
|
+
# rubocop:disable Lint/UselessMethodDefinition
|
42
43
|
# public to allow testing
|
43
44
|
def self.warn(warning)
|
44
45
|
super
|
45
46
|
end
|
47
|
+
|
48
|
+
# rubocop:enable Lint/UselessMethodDefinition
|
46
49
|
end
|
47
50
|
|
48
51
|
class ReadOnlyTextNode < XML::Mapping::TextNode
|
@@ -129,7 +129,7 @@ module Datacite
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def subjects=(value)
|
132
|
-
@subjects =
|
132
|
+
@subjects = value&.select(&:value) || []
|
133
133
|
end
|
134
134
|
|
135
135
|
def contributors=(value)
|
@@ -170,11 +170,11 @@ module Datacite
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def descriptions=(value)
|
173
|
-
@descriptions =
|
173
|
+
@descriptions = value&.select(&:value) || []
|
174
174
|
end
|
175
175
|
|
176
176
|
def geo_locations=(value)
|
177
|
-
@geo_locations =
|
177
|
+
@geo_locations = value&.select(&:location?) || []
|
178
178
|
end
|
179
179
|
|
180
180
|
# @!attribute [rw] identifier
|
@@ -14,7 +14,7 @@ module Datacite
|
|
14
14
|
# @param scheme_uri [URI, nil] the URI of the subject scheme or classification code or authority if one is used. Optional.
|
15
15
|
# @param language [String, nil] an IETF BCP 47, ISO 639-1 language code identifying the language.
|
16
16
|
# @param value [String] the subject itself.
|
17
|
-
def initialize(scheme: nil, scheme_uri: nil, language: nil
|
17
|
+
def initialize(value:, scheme: nil, scheme_uri: nil, language: nil)
|
18
18
|
self.scheme = scheme
|
19
19
|
self.scheme_uri = scheme_uri
|
20
20
|
self.language = language
|
@@ -26,7 +26,7 @@ module Datacite
|
|
26
26
|
# @param language [String, nil] an IETF BCP 47, ISO 639-1 language code identifying the language.
|
27
27
|
# @param value [String] the title itself.
|
28
28
|
# @param type [TitleType, nil] the title type. Optional.
|
29
|
-
def initialize(language: nil,
|
29
|
+
def initialize(value:, language: nil, type: nil)
|
30
30
|
self.language = language
|
31
31
|
self.type = type
|
32
32
|
self.value = value
|
@@ -20,7 +20,7 @@ module Datacite
|
|
20
20
|
iso8601_secs: '1914-08-04T11:01:06+01:00',
|
21
21
|
iso8601_frac: '1914-08-04T11:01:06.0123+01:00'
|
22
22
|
}
|
23
|
-
@dates = values.
|
23
|
+
@dates = values.transform_values { |v| DateValue.new(v) }
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#initialize' do
|