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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 735d8cc7ab80f9534cba40b1b46b38b15dc8124f4e0cd53bb1963c5b31b2a9c2
4
- data.tar.gz: f052e557983ea3af4ea3c025db12daa93ad5e60253f3e427c0cfe1ee39277bf1
3
+ metadata.gz: 5a6ecd59de223d63f3cbdba50679fd649e3b90b5faf54ac5c5d441cfc32c8a6f
4
+ data.tar.gz: ea434e0efa6850179bd6147a95e21ce0f682d6494d950bd7184dcb5eea929cdf
5
5
  SHA512:
6
- metadata.gz: 21645ef65182b9800dd3657188d31dc38a2ce148a910853d667eacaebf20dd334bdcd2ee34c32b85dd5bfa8b681b47a9380b0ab600367af5750a39c80c4ddf35
7
- data.tar.gz: 33c2ff60458e0c835c086b2eff99e5198b26e0783ef483444418cd74e98f715ff4f149534e979fa5f124044924f5ad781088021ca56ad867a0af5ae89fe8c286
6
+ metadata.gz: a2e1ffe1f08383143bea79f9dd4d48404e60ecde812e6c2b089fec7a4ea6ff385b4f6a0e95e1cfda9baee9c6f99a85790c17f7abd0b94b980c44a0e0bebc5464
7
+ data.tar.gz: 5ee1fecb57d8eb8a7ca6a94ea3c2ecc02cf7872896350328ab42a2f292b6f51e599c0c427d5b444daa189f6db645a4ee7bd585dd96989e4b557fa967c0810240
data/.rubocop.yml CHANGED
@@ -42,3 +42,9 @@ Style/ClassAndModuleChildren:
42
42
  Style/MixinUsage:
43
43
  Exclude:
44
44
  - 'examples/*'
45
+
46
+ Style/OptionalBooleanParameter:
47
+ Enabled: false
48
+
49
+ Naming/VariableNumber:
50
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 3.0.4
data/CHANGES.md CHANGED
@@ -1,4 +1,8 @@
1
- ## 0.4.0 (12 November 2019
1
+ ## 0.5.0 (12 November 2019)
2
+ - Update to Ruby 3.0.4
3
+ - Update to Rubocop 0.93
4
+
5
+ ## 0.4.0 (12 November 2019)
2
6
 
3
7
  - Datacite 4.3 support:
4
8
  - Added the new elements and attributes introduced in DataCite 4.1, 4.2, and 4.3.
@@ -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)[^\/]+}, 'http://\1\2'))
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', '~> 1.7'
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', '~> 10.4'
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, value:)
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, type:)
90
+ def initialize(name:, type:, identifier: nil, affiliations: nil)
91
91
  self.name = name
92
92
  self.identifier = identifier
93
93
  self.affiliations = affiliations || []
@@ -9,7 +9,7 @@ module Datacite
9
9
  module Mapping
10
10
  class ContributorName
11
11
  include XML::Mapping
12
- def initialize(type: nil, language: nil, value:)
12
+ def initialize(value:, type: nil, language: nil)
13
13
  self.type = type
14
14
  self.language = language
15
15
  self.value = value
@@ -9,7 +9,7 @@ module Datacite
9
9
  module Mapping
10
10
  class CreatorName
11
11
  include XML::Mapping
12
- def initialize(type: nil, language: nil, value:)
12
+ def initialize(value:, type: nil, language: nil)
13
13
  self.type = type
14
14
  self.language = language
15
15
  self.value = value
@@ -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
- if parts.size == 1
86
+ case parts.size
87
+ when 1
87
88
  @date_value = DateValue.new(val)
88
- elsif parts.size == 2
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.class == self.class
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.class == self.class
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(language: nil, type:, value:)
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, value:)
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, value:)
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
- init_from_hash(args[0])
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.class == self.class
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&.is_a?(geom_class)
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
- init_from_hash(args[0])
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.class == self.class
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)
@@ -25,7 +25,7 @@ module Datacite
25
25
  end
26
26
 
27
27
  def <=>(other)
28
- return nil unless other.class == self.class
28
+ return nil unless other.instance_of?(self.class)
29
29
 
30
30
  points <=> other.points
31
31
  end
@@ -5,7 +5,7 @@ require 'datacite/mapping/empty_filtering_nodes'
5
5
 
6
6
  module Datacite
7
7
  module Mapping
8
- DOI_PATTERN = %r{10\.\S+/\S+}.freeze
8
+ DOI_PATTERN = %r{10\.\S+/\S+}
9
9
 
10
10
  # The persistent identifier that identifies the resource.
11
11
  #
@@ -6,9 +6,9 @@ module Datacite
6
6
  NAME = 'datacite-mapping'
7
7
 
8
8
  # The version of this gem
9
- VERSION = '0.4.0'
9
+ VERSION = '0.5.0'
10
10
 
11
11
  # The copyright notice for this gem
12
- COPYRIGHT = 'Copyright (c) 2019 The Regents of the University of California'
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, value:)
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, value:)
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 = (value&.select(&:value)) || []
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 = (value&.select(&:value)) || []
173
+ @descriptions = value&.select(&:value) || []
174
174
  end
175
175
 
176
176
  def geo_locations=(value)
177
- @geo_locations = (value&.select(&:location?)) || []
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, value:)
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, value:, type: 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.map { |format, v| [format, DateValue.new(v)] }.to_h
23
+ @dates = values.transform_values { |v| DateValue.new(v) }
24
24
  end
25
25
 
26
26
  describe '#initialize' do