datacite-mapping 0.4.1 → 0.6.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.
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'xml/mapping_extensions'
4
+ require 'datacite/mapping/creator'
5
+ require 'datacite/mapping/title'
6
+ require 'datacite/mapping/contributor'
7
+ require 'datacite/mapping/publisher'
8
+
9
+ module Datacite
10
+ module Mapping
11
+
12
+ class NumberType < TypesafeEnum::Base
13
+ # @!parse ARTICLE = Article
14
+ new :ARTICLE, 'Article'
15
+
16
+ # @!parse CHAPTER = Chapter
17
+ new :CHAPTER, 'Chapter'
18
+
19
+ # @!parse REPORT = Report
20
+ new :REPORT, 'Report'
21
+
22
+ # @!parse OTHER = Other
23
+ new :OTHER, 'Other'
24
+ end
25
+
26
+ # @param number_type [identifierType] the type of the related identifier. Cannot be nil.
27
+ class Number
28
+ include XML::Mapping
29
+
30
+ def initialize(value:, number_type:)
31
+ self.value = value
32
+ self.number_type = number_type
33
+ end
34
+
35
+ root_element_name 'number'
36
+
37
+ # @!attribute [rw] number_type
38
+ # @return [NumberType] the type of the related item’s number, e.g., report number or article number.
39
+ typesafe_enum_node :number_type, '@numberType', class: NumberType
40
+
41
+ # @!attribute [rw] value
42
+ # @return [String] the identifier value. Cannot be nil.
43
+ text_node :value, 'text()'
44
+ end
45
+
46
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
47
+
48
+ # @param identifier_type [identifierType] the type of the related identifier. Cannot be nil.
49
+ # @param related_metadata_scheme [String, nil] the name of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
50
+ # @param scheme_uri [URI, nil] the URI of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
51
+ # @param scheme_type [String, nil] the type of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
52
+ class RelatedItemIdentifier
53
+ include XML::Mapping
54
+
55
+ def initialize(value:, identifier_type:, related_metadata_scheme: nil, scheme_uri: nil, scheme_type: nil)
56
+ self.value = value
57
+ self.identifier_type = identifier_type
58
+ self.related_metadata_scheme = related_metadata_scheme
59
+ self.scheme_uri = scheme_uri
60
+ self.scheme_type = scheme_type
61
+ end
62
+
63
+ def value=(value)
64
+ raise ArgumentError, 'Value cannot be empty or nil' unless value && !value.empty?
65
+
66
+ @value = value
67
+ end
68
+
69
+ def identifier_type=(value)
70
+ raise ArgumentError, 'Identifier type cannot be empty or nil' unless value
71
+
72
+ @identifier_type = value
73
+ end
74
+
75
+ root_element_name 'relatedItemIdentifier'
76
+
77
+ # @!attribute [rw] value
78
+ # @return [String] the identifier value. Cannot be nil.
79
+ text_node :value, 'text()'
80
+
81
+ # @!attribute [rw] identifier_type
82
+ # @return [RelatedIdentifierType] the type of the related identifier. Cannot be nil.
83
+ typesafe_enum_node :identifier_type, '@relatedItemIdentifierType', class: RelatedIdentifierType
84
+
85
+ # @!attribute [rw] related_metadata_scheme
86
+ # @return [String, nil] the name of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
87
+ text_node :related_metadata_scheme, '@relatedMetadataScheme', default_value: nil
88
+
89
+ # @!attribute [rw] scheme_uri
90
+ # @return [URI, nil] the URI of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
91
+ uri_node :scheme_uri, '@schemeURI', default_value: nil
92
+
93
+ # @!attribute [rw] scheme_type
94
+ # @return [String, nil] the type of the metadata scheme. Used only with `HasMetadata`/`IsMetadataFor`. Optional.
95
+ text_node :scheme_type, '@schemeType', default_value: nil
96
+ end
97
+
98
+ # Information about a resource related to the one being registered.
99
+ class RelatedItem
100
+ include XML::Mapping
101
+
102
+ attr_writer :related_item_identifier, :creators, :number
103
+
104
+ # Initializes a new {RelatedItem}.
105
+ # @param relation_type [RelationType] the relationship of the {Resource} to the related resource. Cannot be nil.
106
+ # @param relation_type_information [String] additional information about the selected [RelationType], if appropriate.
107
+ # @param value [String] the identifier value. Cannot be nil.
108
+ # @param identifier_type [RelatedItemType] the type of the related identifier. Cannot be nil.
109
+ def initialize(relation_type:, related_item_type:, titles:, relation_type_information: nil, related_item_identifier: nil, creators: [], publication_year: nil, volume: nil, issue: nil, number: nil, first_page: nil, last_page: nil, edition: nil, publisher: nil, contributors: [])
110
+ self.relation_type = relation_type
111
+ self.related_item_type = related_item_type
112
+ self.relation_type_information = relation_type_information
113
+ self.related_item_identifier = related_item_identifier
114
+ self.creators = creators
115
+ self.titles = titles
116
+ self.publication_year = publication_year
117
+ self.volume = volume
118
+ self.issue = issue
119
+ self.number = number
120
+ self.first_page = first_page
121
+ self.last_page = last_page
122
+ self.publisher = publisher
123
+ self.edition = edition
124
+ self.contributors = contributors
125
+ end
126
+
127
+ def relation_type=(value)
128
+ raise ArgumentError, 'Relation type cannot be nil' unless value
129
+
130
+ @relation_type = value
131
+ end
132
+
133
+ def related_item_type=(value)
134
+ raise ArgumentError, 'Identifier type cannot be empty or nil' unless value
135
+
136
+ @related_item_type = value
137
+ end
138
+
139
+ def titles=(value)
140
+ raise ArgumentError, 'RelatedItem must have at least one title' unless value && !value.empty?
141
+
142
+ @titles = value
143
+ end
144
+
145
+ def publication_year=(value)
146
+ raise ArgumentError, 'Resource must have a four-digit publication year' if value.present? && !value&.to_i&.between?(1000, 9999)
147
+
148
+ @publication_year = value.to_i
149
+ end
150
+
151
+ # publisher can be entered as a string or a Publisher object, but it will be stored
152
+ # as a Publisher object
153
+ def publisher=(value)
154
+ @publisher = if value.is_a?(Publisher)
155
+ value
156
+ else
157
+ Publisher.new(value: value)
158
+ end
159
+ end
160
+
161
+ def contributors=(value)
162
+ @contributors = value || []
163
+ end
164
+
165
+ root_element_name 'relatedItem'
166
+
167
+ # @!attribute [rw] related_item_type
168
+ # @return [ResourceTypeGeneral] the general resource type
169
+ typesafe_enum_node :related_item_type, '@relatedItemType', class: ResourceTypeGeneral, default_value: nil
170
+
171
+ # @!attribute [rw] relation_type
172
+ # @return [RelationType] the relationship of the {Resource} to the related resource. Cannot be nil.
173
+ typesafe_enum_node :relation_type, '@relationType', class: RelationType
174
+
175
+ # @!attribute [rw] relation_type_information
176
+ # @return [String, nil] Additional information about the selected relationType, if appropriate. Recommended for use with the relationType Other.
177
+ text_node :relation_type_information, '@rrelationTypeInformation', default_value: nil
178
+
179
+ # @!attribute [rw] related_item_identifier
180
+ # @return [RelatedItemIdentifier, nil] the related item identifier
181
+ object_node :related_item_identifier, 'relatedItemIdentifier', class: RelatedItemIdentifier, default_value: nil
182
+
183
+ # @!attribute [rw] creators
184
+ # @return [Array<Creator>] the main researchers involved working on the data, or the authors of the publication in priority order.
185
+ array_node :creators, 'creators', 'creator', class: Creator
186
+
187
+ # @!attribute [rw] titles
188
+ # @return [Array<Title>] the names or titles by which a resource is known.
189
+ array_node :titles, 'titles', 'title', class: Title
190
+
191
+ # @!attribute [rw] volume
192
+ # @return [String] Volume of the related item.
193
+ text_node :volume, 'volume', default_value: nil
194
+
195
+ # @!attribute [rw] issue
196
+ # @return [String] Issue number or name of the related item.
197
+ text_node :issue, 'issue', default_value: nil
198
+
199
+ # @!attribute [rw] related_item_identifier
200
+ # @return [RelatedItemIdentifier, nil] the related item identifier
201
+ object_node :number, 'number', class: Number, default_value: nil
202
+
203
+ # @!attribute [rw] firstPage
204
+ # @return [String] First page of the resource within the related item, e.g., of the chapter, article, or conference paper in proceedings.
205
+ text_node :first_page, 'firstPage', default_value: nil
206
+
207
+ # @!attribute [rw] lastPage
208
+ # @return [String] Last page of the resource within the related item, e.g., of the chapter, article, or conference paper in proceedings.
209
+ text_node :last_page, 'lastPage', default_value: nil
210
+
211
+ # @!attribute [rw] publisher
212
+ # @return [Publisher] the name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource.
213
+ object_node :publisher, 'publisher', class: Publisher
214
+
215
+ # @!attribute [rw] edition
216
+ # @return [String] Edition of the related item.
217
+ text_node :edition, 'edition', default_value: nil
218
+
219
+ # @!attribute [rw] contributors
220
+ # @return [Array<Contributor>] institutions or persons responsible for collecting, creating, or otherwise contributing to the developement of the dataset.
221
+ array_node :contributors, 'contributors', 'contributor', class: Contributor, default_value: []
222
+ end
223
+
224
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
225
+ end
226
+ end
@@ -13,6 +13,7 @@ require 'datacite/mapping/alternate_identifier'
13
13
  require 'datacite/mapping/rights'
14
14
  require 'datacite/mapping/geo_location'
15
15
  require 'datacite/mapping/read_only_nodes'
16
+ require 'datacite/mapping/related_item'
16
17
 
17
18
  module Datacite
18
19
  module Mapping
@@ -76,6 +77,7 @@ module Datacite
76
77
  self.resource_type = resource_type
77
78
  self.alternate_identifiers = alternate_identifiers
78
79
  self.related_identifiers = related_identifiers
80
+ self.related_items = related_items
79
81
  self.sizes = sizes
80
82
  self.formats = formats
81
83
  self.version = version
@@ -129,7 +131,7 @@ module Datacite
129
131
  end
130
132
 
131
133
  def subjects=(value)
132
- @subjects = (value&.select(&:value)) || []
134
+ @subjects = value&.select(&:value) || []
133
135
  end
134
136
 
135
137
  def contributors=(value)
@@ -152,6 +154,10 @@ module Datacite
152
154
  @related_identifiers = value || []
153
155
  end
154
156
 
157
+ def related_items=(value)
158
+ @related_items = value || []
159
+ end
160
+
155
161
  def sizes=(value)
156
162
  @sizes = value || []
157
163
  end
@@ -170,11 +176,11 @@ module Datacite
170
176
  end
171
177
 
172
178
  def descriptions=(value)
173
- @descriptions = (value&.select(&:value)) || []
179
+ @descriptions = value&.select(&:value) || []
174
180
  end
175
181
 
176
182
  def geo_locations=(value)
177
- @geo_locations = (value&.select(&:location?)) || []
183
+ @geo_locations = value&.select(&:location?) || []
178
184
  end
179
185
 
180
186
  # @!attribute [rw] identifier
@@ -233,6 +239,10 @@ module Datacite
233
239
  # @return [Array<RelatedIdentifier>] identifiers of related resources.
234
240
  array_node :related_identifiers, 'relatedIdentifiers', 'relatedIdentifier', class: RelatedIdentifier, default_value: []
235
241
 
242
+ # @!attribute [rw] related_items
243
+ # @return [Array<RelatedItems>] descriptions of related resources.
244
+ array_node :related_items, 'relatedItems', 'relatedItem', class: RelatedItem, default_value: []
245
+
236
246
  # @!attribute [rw] sizes
237
247
  # @return [Array<String>] unstructured size information about the resource.
238
248
  array_node :sizes, 'sizes', 'size', class: String, default_value: []
@@ -305,6 +315,8 @@ module Datacite
305
315
 
306
316
  read_only_array_node :funding_references, 'fundingReferences', 'fundingReference', class: FundingReference, default_value: [], warn_reason: '<fundingReferences/> not supported in Datacite 3'
307
317
 
318
+ read_only_array_node :related_items, 'relatedItems', 'relatedItem', class: RelatedItem, default_value: [], warn_reason: '<relatedItems/> not supported in Datacite 3'
319
+
308
320
  fallback_mapping :datacite_3, :_default
309
321
  end
310
322
 
@@ -10,30 +10,81 @@ module Datacite
10
10
  # @!parse AUDIOVISUAL = Audiovisual
11
11
  new :AUDIOVISUAL, 'Audiovisual'
12
12
 
13
+ # @!parse AWARD = Award
14
+ new :AWARD, 'Award'
15
+
16
+ # @!parse BOOK = Book
17
+ new :BOOK, 'Book'
18
+
19
+ # @!parse BOOK_CHAPTER = BookChapter
20
+ new :BOOK_CHAPTER, 'BookChapter'
21
+
13
22
  # @!parse COLLECTION = Collection
14
23
  new :COLLECTION, 'Collection'
15
24
 
25
+ # @!parse COMPUTATIONAL_NOTEBOOK = ComputationalNotebook
26
+ new :COMPUTATIONAL_NOTEBOOK, 'ComputationalNotebook'
27
+
28
+ # @!parse CONFERENCE_PAPER = ConferencePaper
29
+ new :CONFERENCE_PAPER, 'ConferencePaper'
30
+
31
+ # @!parse CONFERENCE_PROCEEDING = ConferenceProceeding
32
+ new :CONFERENCE_PROCEEDING, 'ConferenceProceeding'
33
+
16
34
  # @!parse DATASET = Dataset
17
35
  new :DATASET, 'Dataset'
18
36
 
19
37
  # @!parse DATA_PAPER = DataPaper
20
38
  new :DATA_PAPER, 'DataPaper'
21
39
 
40
+ # @!parse DISSERTATION = Dissertation
41
+ new :DISSERTATION, 'Dissertation'
42
+
22
43
  # @!parse EVENT = Event
23
44
  new :EVENT, 'Event'
24
45
 
25
46
  # @!parse IMAGE = Image
26
47
  new :IMAGE, 'Image'
27
48
 
49
+ # @!parse INSTRUMENT = Instrument
50
+ new :INSTRUMENT, 'Instrument'
51
+
52
+ # @!parse JOURNAL = Journal
53
+ new :JOURNAL, 'Journal'
54
+
55
+ # @!parse JOURNAL_ARTICLE = JournalArticle
56
+ new :JOURNAL_ARTICLE, 'JournalArticle'
57
+
28
58
  # @!parse INTERACTIVE_RESOURCE = InteractiveResource
29
59
  new :INTERACTIVE_RESOURCE, 'InteractiveResource'
30
60
 
31
61
  # @!parse MODEL = Model
32
62
  new :MODEL, 'Model'
33
63
 
64
+ # @!parse OUTPUT_MANAGEMENT_PLAN = OutputManagementPlan
65
+ new :OUTPUT_MANAGEMENT_PLAN, 'OutputManagementPlan'
66
+
67
+ # @!parse PEER_REVIEW = PeerReview
68
+ new :PEER_REVIEW, 'PeerReview'
69
+
34
70
  # @!parse PHYSICAL_OBJECT = PhysicalObject
35
71
  new :PHYSICAL_OBJECT, 'PhysicalObject'
36
72
 
73
+ # @!parse POSTER = Poster
74
+ new :POSTER, 'Poster'
75
+
76
+ # @!parse PREPRINT = Preprint
77
+ new :PREPRINT, 'Preprint'
78
+
79
+ # @!parse PRESENTATION = Presentation
80
+ new :PRESENTATION, 'Presentation'
81
+
82
+ # @!parse PROJECT = Project
83
+ new :PROJECT, 'Project'
84
+
85
+ # @!parse REPORT = Report
86
+ new :REPORT, 'Report'
87
+
37
88
  # @!parse SERVICE = Service
38
89
  new :SERVICE, 'Service'
39
90
 
@@ -43,6 +94,12 @@ module Datacite
43
94
  # @!parse SOUND = Sound
44
95
  new :SOUND, 'Sound'
45
96
 
97
+ # @!parse STANDARD = Standard
98
+ new :STANDARD, 'Standard'
99
+
100
+ # @!parse STUDY_REGISTRATION = StudyRegistration
101
+ new :STUDY_REGISTRATION, 'StudyRegistration'
102
+
46
103
  # @!parse TEXT = Text
47
104
  new :TEXT, 'Text'
48
105
 
@@ -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
@@ -44,6 +44,10 @@ module Datacite
44
44
  # @return [String, nil] an IETF BCP 47, ISO 639-1 language code identifying the language.
45
45
  text_node :language, '@xml:lang', default_value: nil
46
46
 
47
+ # @!attribute [rw] classification_code
48
+ # @return [String, nil] the classification code used for the subject term in the subject scheme.
49
+ text_node :classification_code, '@classificationCode', default_value: nil
50
+
47
51
  # @!attribute [rw] value
48
52
  # @return [String] the subject itself.
49
53
  text_node :value, 'text()'
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ if ENV['COVERAGE']
12
12
  add_filter '/spec/'
13
13
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
14
  SimpleCov::Formatter::HTMLFormatter,
15
- SimpleCov::Formatter::Console,
15
+ SimpleCov::Formatter::Console
16
16
  ]
17
17
  end
18
18
  end
@@ -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