bolognese 0.9.18 → 0.9.19

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
  SHA1:
3
- metadata.gz: 1463edb9e56dc1c3519c19a325f248d9e8d134d0
4
- data.tar.gz: 44484bf41d55c1539b38f39bf6111bacead7e447
3
+ metadata.gz: 8e774c4a8a3e9c8e2d6632ed0e6356bb9c54d611
4
+ data.tar.gz: 8230a49968ca28458cc71a55f57d90864db48b17
5
5
  SHA512:
6
- metadata.gz: a981e4ba58d96e9e2e67ae7ce15fd18a951ba3364d06723271d55634e2ccbda9a31bb882c96a9ad1f6ba4489b2537de8f7610f8d2c3dfaa48d7624c98d9fc537
7
- data.tar.gz: fbb30ce05de64f05402a8e62b4a8d5617e26f0b7331a53ad3cd1a848fc46293b46d0c2bb35ac072f70fd5196ac1d3b5ccbd45e3a7bf216a78448ec5ad1add403
6
+ metadata.gz: 55998c995185346c175798ee00517892aa0ac0bf5ed0059d751b38210421e501fd3b3dc7b51a20e2c43ae5803c04ff806e33b48acab134bc0966b28604937231
7
+ data.tar.gz: af2db0282a846b976d26f9c18e7e1e5561d28fcaa2949b0c43751c3ec3818058797fa34403de5411d24bfe93eead5d3d72bbb321bf45659e937b8a0f889be33a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bolognese (0.9.18)
4
+ bolognese (0.9.19)
5
5
  activesupport (>= 4.2.5, < 6)
6
6
  benchmark_methods (~> 0.7)
7
7
  bibtex-ruby (~> 4.1)
@@ -118,6 +118,28 @@ module Bolognese
118
118
  end.uniq
119
119
  end
120
120
 
121
+ def datacite_funder_contributor(meta)
122
+ Array.wrap(meta.dig("contributors", "contributor")).reduce([]) do |sum, f|
123
+ if f["contributorType"] == "Funder"
124
+ # handle special case of OpenAIRE metadata
125
+ id = f.dig("nameIdentifier", "__content__").to_s.start_with?("info:eu-repo/grantAgreement/EC") ? "https://doi.org/10.13039/501100000780" : nil
126
+
127
+ funder = { "type" => "Organization",
128
+ "id" => id,
129
+ "name" => f["contributorName"] }.compact
130
+ if f.dig("nameIdentifier", "nameIdentifierScheme") == "info"
131
+ sum << { "type" => "Award",
132
+ "identifier" => f.dig("nameIdentifier", "__content__").split("/").last,
133
+ "funder" => funder }
134
+ else
135
+ sum << funder
136
+ end
137
+ else
138
+ sum
139
+ end
140
+ end
141
+ end
142
+
121
143
  def datacite_related_identifier(meta, relation_type: nil)
122
144
  arr = Array.wrap(meta.dig("relatedIdentifiers", "relatedIdentifier")).select { |r| %w(DOI URL).include?(r["relatedIdentifierType"]) }
123
145
  arr = arr.select { |r| relation_type.split(" ").include?(r["relationType"]) } if relation_type.present?
@@ -176,24 +198,6 @@ module Bolognese
176
198
  def datacite_is_reviewed_by(meta)
177
199
  datacite_related_identifier(meta, relation_type: "IsReviewedBy").presence
178
200
  end
179
-
180
- def datacite_funder_contributor(meta)
181
- Array.wrap(meta.dig("contributors", "contributor")).reduce([]) do |sum, f|
182
- if f["contributorType"] == "Funder"
183
- funder = { "type" => "Organization",
184
- "name" => f["contributorName"] }.compact
185
- if f.dig("nameIdentifier", "nameIdentifierScheme") == "info"
186
- sum << { "type" => "Award",
187
- "identifier" => f.dig("nameIdentifier", "__content__").split("/").last,
188
- "funder" => funder }
189
- else
190
- sum << funder
191
- end
192
- else
193
- sum
194
- end
195
- end
196
- end
197
201
  end
198
202
  end
199
203
  end
@@ -383,19 +383,28 @@ module Bolognese
383
383
  end
384
384
 
385
385
  def to_schema_org(element)
386
- Array.wrap(element).map do |a|
387
- a["@type"] = a["type"]
388
- a["@id"] = a["id"]
389
- a["name"] = a["title"] if a["title"].present?
390
- a.except("type", "id", "title").compact
391
- end.unwrap
386
+ mapping = { "type" => "@type", "id" => "@id", "title" => "name" }
387
+
388
+ map_hash_keys(element: element, mapping: mapping)
392
389
  end
393
390
 
394
391
  def from_schema_org(element)
392
+ mapping = { "@type" => "type", "@id" => "id" }
393
+
394
+ map_hash_keys(element: element, mapping: mapping)
395
+ end
396
+
397
+ def map_hash_keys(element: nil, mapping: nil)
395
398
  Array.wrap(element).map do |a|
396
- a["type"] = a["@type"]
397
- a["id"] = a["@id"]
398
- a.except("@type", "@id").compact
399
+ a.map {|k, v| [mapping.fetch(k, k), v] }.reduce({}) do |hsh, (k, v)|
400
+ if v.is_a?(Hash)
401
+ hsh[k] = to_schema_org(v)
402
+ hsh
403
+ else
404
+ hsh[k] = v
405
+ hsh
406
+ end
407
+ end
399
408
  end.unwrap
400
409
  end
401
410
 
@@ -1,3 +1,3 @@
1
1
  module Bolognese
2
- VERSION = "0.9.18"
2
+ VERSION = "0.9.19"
3
3
  end
@@ -38,7 +38,7 @@ module Bolognese
38
38
  "issue" => issue,
39
39
  "pagination" => pagination,
40
40
  "spatial_coverage" => spatial_coverage,
41
- "funding_reference" => funding,
41
+ "funding" => funding,
42
42
  "schema_version" => schema_version,
43
43
  "provider" => provider
44
44
  }.compact
@@ -124,7 +124,7 @@ describe Bolognese::Metadata, vcr: true do
124
124
  expect(subject.description["text"]).to start_with("The dataset contains a sample of metadata describing papers")
125
125
  expect(subject.date_published).to eq("2013-04-03")
126
126
  expect(subject.publisher).to eq("OpenAIRE Orphan Record Repository")
127
- expect(subject.funding).to eq("type"=>"Award", "identifier"=>"246686", "funder"=>{"type"=>"Organization", "name"=>"European Commission"})
127
+ expect(subject.funding).to eq("type"=>"Award", "identifier"=>"246686", "funder"=>{"type"=>"Organization", "id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"})
128
128
  expect(subject.provider).to eq("DataCite")
129
129
  expect(subject.schema_version).to eq("http://datacite.org/schema/kernel-3")
130
130
  end
@@ -81,7 +81,7 @@ describe Bolognese::Metadata, vcr: true do
81
81
  json = JSON.parse(subject.schema_org)
82
82
  expect(json["@id"]).to eq("https://doi.org/10.5438/6423")
83
83
  expect(json["funding"]).to eq("@type" => "Award",
84
- "funder" => {"type"=>"Organization", "id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
84
+ "funder" => {"@type"=>"Organization", "@id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
85
85
  "identifier" => "654039",
86
86
  "name" => "THOR – Technical and Human Infrastructure for Open Research",
87
87
  "url" => "http://cordis.europa.eu/project/rcn/194927_en.html")
@@ -93,7 +93,7 @@ describe Bolognese::Metadata, vcr: true do
93
93
  json = JSON.parse(subject.schema_org)
94
94
  expect(json["@id"]).to eq("https://doi.org/10.5281/zenodo.1239")
95
95
  expect(json["funding"]).to eq("@type" => "Award",
96
- "funder" => {"type"=>"Organization", "name"=>"European Commission"},
96
+ "funder" => {"@type"=>"Organization", "@id"=>"https://doi.org/10.13039/501100000780", "name"=>"European Commission"},
97
97
  "identifier" => "246686")
98
98
  end
99
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolognese
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.18
4
+ version: 0.9.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner