commonmeta-ruby 3.4.2 → 3.4.4

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: 6e7e0078d9ee8268350debef90ecae5249f626498dc89630a1671a2edd16e4fc
4
- data.tar.gz: a9265add9afeb7a302503da01875574d0ff999e2f93928ed324fabd5e0faaacc
3
+ metadata.gz: c5c580fb509592f279c823dff8e3706420d08af27e2fbf34eae997ab27138b35
4
+ data.tar.gz: 44ac2df8b90492d35c45d125f4b9d4c5800827a17acde4c50453af49e5b04160
5
5
  SHA512:
6
- metadata.gz: c248850455ab14549458e9fbaa46309d03a0cfdd9836ecdaf2681eba606c5036480a66c4458c3b5fd140632fd1e8b4b7b1bcce79bfbf997cb694ba8dc974d66a
7
- data.tar.gz: 5ae480537efd8c91dbeb013ff071189b340bc13e6a34b784c1a1d9af699dd2b0a123029758c1018ac40d921bd0444829d7b40938d89acf85ebd189228cb9226b
6
+ metadata.gz: ece0ebc5a0e2028704029c9eb97318721d532b2f9eb580c9dbf5419784e10a34176925517790c0bd6819e7f9d5dfd807f8f97afb9ec5722f4255c0c4065724e1
7
+ data.tar.gz: a12d1a02e8ce66d1f3c6ed4ca7672b9dbf54413f1e3c336fed6a7fa6f3f53a73e2bdf937f8d4d32faf2c4e40fd41357b043813adde42c5387bb528d1fb6c86fa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- commonmeta-ruby (3.4.2)
4
+ commonmeta-ruby (3.4.4)
5
5
  activesupport (>= 4.2.5, < 8.0)
6
6
  addressable (~> 2.8.1, < 2.8.2)
7
7
  base32-url (>= 0.7.0, < 1)
@@ -62,6 +62,7 @@ module Commonmeta
62
62
  insert_crossref_abstract(xml)
63
63
  insert_crossref_issn(xml)
64
64
  insert_item_number(xml)
65
+ insert_funding_references(xml)
65
66
  insert_crossref_access_indicators(xml)
66
67
  insert_crossref_relations(xml)
67
68
  insert_doi_data(xml)
@@ -81,6 +82,7 @@ module Commonmeta
81
82
  insert_institution(xml)
82
83
  insert_item_number(xml)
83
84
  insert_crossref_abstract(xml)
85
+ insert_funding_references(xml)
84
86
  insert_crossref_access_indicators(xml)
85
87
  insert_crossref_relations(xml)
86
88
  insert_doi_data(xml)
@@ -99,7 +101,7 @@ module Commonmeta
99
101
  Array.wrap(creators).each_with_index do |creator, index|
100
102
  if creator["type"] == "Organization" && creator["name"].present?
101
103
  xml.organization(creator["name"], "contributor_role" => "author",
102
- "sequence" => index.zero? ? "first" : "additional")
104
+ "sequence" => index.zero? ? "first" : "additional")
103
105
  elsif creator["givenName"].present? || creator["familyName"].present?
104
106
  xml.person_name("contributor_role" => "author",
105
107
  "sequence" => index.zero? ? "first" : "additional") do
@@ -128,7 +130,7 @@ module Commonmeta
128
130
  xml.affiliations do
129
131
  xml.institution do
130
132
  xml.institution_name(creator.dig("affiliation", 0, "name")) if creator.dig("affiliation", 0, "name").present?
131
- xml.institution_id(creator.dig("affiliation", 0, "id"), 'type' => "ror") if creator.dig("affiliation", 0, "id").present?
133
+ xml.institution_id(creator.dig("affiliation", 0, "id"), "type" => "ror") if creator.dig("affiliation", 0, "id").present?
132
134
  end
133
135
  end
134
136
  end
@@ -138,7 +140,7 @@ module Commonmeta
138
140
  xml.affiliations do
139
141
  xml.institution do
140
142
  xml.institution_name(creator.dig("affiliation", 0, "name")) if creator.dig("affiliation", 0, "name").present?
141
- xml.institution_id(creator.dig("affiliation", 0, "id"), 'type' => "ror") if creator.dig("affiliation", 0, "id").present?
143
+ xml.institution_id(creator.dig("affiliation", 0, "id"), "type" => "ror") if creator.dig("affiliation", 0, "id").present?
142
144
  end
143
145
  end
144
146
  end
@@ -209,7 +211,7 @@ module Commonmeta
209
211
  identifier_type = validate_doi(related_identifier["id"]) ? "doi" : "uri"
210
212
  id = identifier_type == "doi" ? doi_from_url(related_identifier["id"]) : related_identifier["id"]
211
213
  attributes = {
212
- "relation-type" => related_identifier["type"].camelize(:lower),
214
+ "relationship-type" => related_identifier["type"].camelize(:lower),
213
215
  "identifier-type" => identifier_type,
214
216
  }.compact
215
217
 
@@ -218,7 +220,7 @@ module Commonmeta
218
220
  end
219
221
  end
220
222
  end
221
-
223
+
222
224
  # def insert_dates(xml)
223
225
  # return xml unless Array.wrap(dates).present?
224
226
 
@@ -230,20 +232,21 @@ module Commonmeta
230
232
  # end
231
233
  # end
232
234
 
233
- # def insert_funding_references(xml)
234
- # return xml unless Array.wrap(funding_references).present?
235
-
236
- # xml.fundingReferences do
237
- # Array.wrap(funding_references).each do |funding_reference|
238
- # xml.fundingReference do
239
- # xml.funderName(funding_reference["funderName"])
240
- # xml.funderIdentifier(funding_reference["funderIdentifier"], { "funderIdentifierType" => funding_reference["funderIdentifierType"] }.compact) if funding_reference["funderIdentifier"].present?
241
- # xml.awardNumber(funding_reference["awardNumber"], { "awardURI" => funding_reference["awardUri"] }.compact) if funding_reference["awardNumber"].present? || funding_reference["awardUri"].present?
242
- # xml.awardTitle(funding_reference["awardTitle"]) if funding_reference["awardTitle"].present?
243
- # end
244
- # end
245
- # end
246
- # end
235
+ def insert_funding_references(xml)
236
+ return xml if funding_references.blank?
237
+
238
+ xml.program("xmlns" => "http://www.crossref.org/fundref.xsd",
239
+ "name" => "fundref") do
240
+ funding_references.each do |funding_reference|
241
+ xml.assertion("name" => "fundgroup") do
242
+ xml.assertion(funding_reference["funderName"], "name" => "funder_name") do
243
+ xml.assertion(funding_reference["funderIdentifier"], "name" => "funder_identifier")
244
+ end
245
+ xml.assertion(funding_reference["awardNumber"], "name" => "award_number")
246
+ end
247
+ end
248
+ end
249
+ end
247
250
 
248
251
  def insert_crossref_subjects(xml)
249
252
  return xml unless subjects.present?
@@ -62,6 +62,7 @@ module Commonmeta
62
62
  sum
63
63
  end
64
64
  references = get_references(meta)
65
+ funding_references = get_funding_references(meta)
65
66
  related_identifiers = get_related_identifiers(meta)
66
67
  alternate_identifiers = [{ "alternateIdentifier" => meta["id"], "alternateIdentifierType" => "UUID" }]
67
68
 
@@ -78,6 +79,7 @@ module Commonmeta
78
79
  "license" => license,
79
80
  "subjects" => subjects.presence,
80
81
  "references" => references.presence,
82
+ "funding_references" => funding_references.presence,
81
83
  "related_identifiers" => related_identifiers.presence,
82
84
  "alternate_identifiers" => alternate_identifiers,
83
85
  "state" => state }.compact.merge(read_options)
@@ -89,10 +91,10 @@ module Commonmeta
89
91
  begin
90
92
  if reference["doi"] && validate_doi(reference["doi"])
91
93
  response = HTTP.follow
92
- .headers(:accept => "application/vnd.citationstyles.csl+json")
93
- .get(reference["doi"])
94
+ .headers(:accept => "application/vnd.citationstyles.csl+json")
95
+ .get(reference["doi"])
94
96
  csl = JSON.parse(response.body.to_s)
95
- sum << reference.merge("title" => csl['title'], "publicationYear" => csl.dig("issued", "date-parts", 0, 0).to_s) if [200, 301, 302].include? response.status
97
+ sum << reference.merge("title" => csl["title"], "publicationYear" => csl.dig("issued", "date-parts", 0, 0).to_s) if [200, 301, 302].include? response.status
96
98
  elsif reference["url"] && validate_url(reference["url"]) == "URL"
97
99
  sum << reference if [200, 301, 302].include? HTTP.head(reference["url"]).status
98
100
  end
@@ -106,10 +108,11 @@ module Commonmeta
106
108
  end
107
109
 
108
110
  def get_related_identifiers(meta)
109
- # check that relationships resolve
111
+ # check that relationships resolve and has a supported type
112
+ supported_types = %w[IsIdenticalTo isPreprintOf isTranslationOf]
110
113
  Array.wrap(meta["relationships"]).reduce([]) do |sum, relationship|
111
114
  begin
112
- if [200, 301, 302].include? HTTP.head(relationship["url"]).status
115
+ if supported_types.include?(relationship["type"]) && [200, 301, 302].include?(HTTP.head(relationship["url"]).status)
113
116
  sum << { "id" => relationship["url"], "type" => relationship["type"] }
114
117
  end
115
118
  rescue => error
@@ -121,6 +124,32 @@ module Commonmeta
121
124
  end
122
125
  end
123
126
 
127
+ def get_funding_references(meta)
128
+ # check that relationships resolve and have type "HasAward"
129
+ Array.wrap(meta["relationships"]).reduce([]) do |sum, relationship|
130
+ begin
131
+ # funder is European Commission
132
+ if validate_prefix(relationship["url"]) == "10.3030" || URI.parse(relationship["url"]).host == "cordis.europa.eu"
133
+ relationship["funderIdentifier"] = "http://doi.org/10.13039/501100000780"
134
+ relationship["funderName"] = "European Commission"
135
+ relationship["awardNumber"] = relationship["url"].split("/").last
136
+ end
137
+ if relationship["type"] == "HasAward" && relationship["funderName"]
138
+ sum << {
139
+ "funderIdentifier" => relationship["funderIdentifier"],
140
+ "funderName" => relationship["funderName"],
141
+ "awardNumber" => relationship["awardNumber"],
142
+ }
143
+ end
144
+ rescue => error
145
+ # puts "Error: #{error.message}"
146
+ # puts "Error: #{reference}"
147
+ end
148
+
149
+ sum
150
+ end
151
+ end
152
+
124
153
  def get_json_feed_unregistered
125
154
  # get JSON Feed items not registered as DOIs
126
155
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commonmeta
4
- VERSION = '3.4.2'
4
+ VERSION = '3.4.4'
5
5
  end