relaton-doi 1.14.0 → 1.14.1

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: d864a698c9f38895e2d9c357d4d2d1cec68e645a08a6f440507fc3a236b1f671
4
- data.tar.gz: ac0782cd81ba541658b97832c3f1efbf4d460c06ba1a720af369b28c70159795
3
+ metadata.gz: 53cd51733991e0f69cc3d0323cd9dff42122523c3a8f2d8e2738b1408da5321b
4
+ data.tar.gz: 7de2c0a2b3fa4369a832eaf1d655349bfe1682d86fc833da07be0243fadb7602
5
5
  SHA512:
6
- metadata.gz: 2e59c3acb8542e99deae9493eec3fdb364f8372feb24ab6f614a62dd8045deb56a12e17013cd21bc7fb33b587fb94e808e53f0bd0c0a44b169985e285312e4d6
7
- data.tar.gz: d0c79b69008ffe853814235600a9c6c693bd027d8c7a38c9813d24933903faa29064f46a54ca6984b0dc14644f74e7a121ba9b2ec223bd2a4aa09625c67b424b
6
+ metadata.gz: 4981dfeb396011af9fa1773f565009306664828231709d0e9d8ffa939f8e6f170dd09b4fe0793a5abbbcea07d024444737359a21e4e433c1b191f97fa245fc24
7
+ data.tar.gz: d599da84e5f7a0468decc094d449e7223dd63b5ff4a615993f34c882f43572fa9bb2287411228de21fc60c37c8c1b3572ae207b142335d4f618c6f8ad0d748c8
@@ -5,7 +5,6 @@ name: rake
5
5
  on:
6
6
  push:
7
7
  branches: [ master, main ]
8
- tags: [ v* ]
9
8
  pull_request:
10
9
 
11
10
  jobs:
@@ -110,9 +110,15 @@ module RelatonDoi
110
110
  doctype: @message["type"],
111
111
  place: create_place,
112
112
  relation: create_relation,
113
+ extent: create_extent,
113
114
  }
114
115
  end
115
116
 
117
+ #
118
+ # Parse the document type.
119
+ #
120
+ # @return [String] The document type.
121
+ #
116
122
  def parse_type
117
123
  TYPES[@message["type"]] || @message["type"]
118
124
  end
@@ -169,9 +175,17 @@ module RelatonDoi
169
175
  # @return [Array<RelatonBib::TypedUri>] The link.
170
176
  #
171
177
  def create_link
172
- return [] unless @message["URL"]
178
+ links = []
179
+ if @message["URL"]
180
+ links << RelatonBib::TypedUri.new(type: "DOI", content: @message["URL"])
181
+ end
182
+ return links unless @message["link"]&.any?
173
183
 
174
- [RelatonBib::TypedUri.new(type: "DOI", content: @message["URL"])]
184
+ link = @message["link"].first
185
+ if link["URL"].match?(/\.pdf$/)
186
+ links << RelatonBib::TypedUri.new(type: "pdf", content: link["URL"])
187
+ end
188
+ links
175
189
  end
176
190
 
177
191
  #
@@ -194,15 +208,33 @@ module RelatonDoi
194
208
  #
195
209
  # @return [Array<RelatonBib::ContributionInfo>] The contributors.
196
210
  #
197
- def create_contributors
211
+ def create_contributors # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
198
212
  contribs = %w[author editor translator].each_with_object([]) do |type, obj|
199
213
  @message[type]&.each do |contrib|
200
214
  obj << contributor(person(contrib), type)
201
215
  end
202
216
  end
217
+ contribs += fetch_editors if contribs.none? { |e| e.role.any? { |r| r.type == "editor" } }
203
218
  contribs << contributor(org_publisher, "publisher")
204
219
  end
205
220
 
221
+ #
222
+ # Fetch editors from Crossref.
223
+ #
224
+ # @return [Array<RelatonBib::ContributionInfo>] The editors.
225
+ #
226
+ def fetch_editors # rubocop:disable Metrics/AbcSize
227
+ title = @message["container-title"].first
228
+ year = (@message["published"] || @message["approved"])["date-parts"][0][0]
229
+ query = "#{title}, #{@message['publisher']}, #{@message['publisher-location']}, #{year}"
230
+ resp = Faraday.get %{http://api.crossref.org/works?query.bibliographic="#{query}"&rows=5&filter=type:book}
231
+ json = JSON.parse resp.body
232
+ item = json["message"]["items"].detect { |i| i["title"].include?(title) && i["editor"] }
233
+ return [] unless item
234
+
235
+ item["editor"].map { |a| contributor(person(a), "editor") }
236
+ end
237
+
206
238
  #
207
239
  # Cerate an organization publisher from the message hash.
208
240
  #
@@ -355,13 +387,30 @@ module RelatonDoi
355
387
  #
356
388
  # @return [Array<RelatonBib::DocumentRelation>] The relations.
357
389
  #
358
- def create_relation
359
- @message["relation"].map do |k, v|
390
+ def create_relation # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
391
+ rels = []
392
+ @message["container-title"]&.each do |ct|
393
+ bib = RelatonBib::BibliographicItem.new(title: [content: ct])
394
+ rels << RelatonBib::DocumentRelation.new(type: "includedIn", bibitem: bib)
395
+ end
396
+ @message["relation"].each_with_object(rels) do |(k, v), a|
360
397
  fref = RelatonBib::FormattedRef.new(content: v["id"])
361
398
  bib = create_bibitem v["id"], formattedref: fref
362
399
  type = REALATION_TYPES[k] || k
363
- RelatonBib::DocumentRelation.new(type: type, bibitem: bib)
400
+ a << RelatonBib::DocumentRelation.new(type: type, bibitem: bib)
364
401
  end
365
402
  end
403
+
404
+ #
405
+ # Create an extent from the message hash.
406
+ #
407
+ # @return [Array<RelatonBib::Locality>] The extent.
408
+ #
409
+ def create_extent
410
+ return [] unless @message["page"]
411
+
412
+ from, to = @message["page"].split("-")
413
+ [RelatonBib::Locality.new("page", from, to)]
414
+ end
366
415
  end
367
416
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonDoi
4
- VERSION = "1.14.0"
4
+ VERSION = "1.14.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-doi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-08 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml