lib/briard/doi_utils.rb in briard-2.4.2 vs lib/briard/doi_utils.rb in briard-2.6.0
- old
+ new
@@ -1,37 +1,37 @@
# frozen_string_literal: true
module Briard
module DoiUtils
def validate_doi(doi)
- doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(doi)).last
+ doi = Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match(doi)).last
# remove non-printing whitespace and downcase
doi.delete("\u200B").downcase if doi.present?
end
def validate_funder_doi(doi)
- doi = Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.13039\/)?([1-9]\d+)\z/.match(doi)).last
+ doi = Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.13039/)?([1-9]\d+)\z}.match(doi)).last
# remove non-printing whitespace and downcase
if doi.present?
doi.delete("\u200B").downcase
"https://doi.org/10.13039/#{doi}"
end
end
def validate_prefix(doi)
- Array(/\A(?:(http|https):\/(\/)?(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}).*\z/.match(doi)).last
+ Array(%r{\A(?:(http|https):/(/)?(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}).*\z}.match(doi)).last
end
def doi_resolver(doi, options = {})
- sandbox = Array(/handle.stage.datacite.org/.match(doi)).last
- sandbox.present? || options[:sandbox] ? "https://handle.stage.datacite.org/" : "https://doi.org/"
+ sandbox = Array(/handle\.stage\.datacite\.org/.match(doi)).last
+ sandbox.present? || options[:sandbox] ? 'https://handle.stage.datacite.org/' : 'https://doi.org/'
end
def doi_api_url(doi, options = {})
- sandbox = Array(/handle.stage.datacite.org/.match(doi)).last
- sandbox.present? || options[:sandbox] ? "https://api.stage.datacite.org/dois/#{doi_from_url(doi)}?include=media,client" : "https://api.datacite.org/dois/#{doi_from_url(doi)}?include=media,client"
+ sandbox = Array(/handle\.stage\.datacite.\org/.match(doi)).last
+ sandbox.present? || options[:sandbox] ? "https://api.stage.datacite.org/dois/#{doi_from_url(doi)}?include=media,client" : "https://api.datacite.org/dois/#{doi_from_url(doi)}?include=media,client"
end
def normalize_doi(doi, options = {})
doi_str = validate_doi(doi)
return nil unless doi_str.present?
@@ -39,13 +39,13 @@
# turn DOI into URL, escape unsafe characters
doi_resolver(doi, options) + Addressable::URI.encode(doi_str)
end
def doi_from_url(url)
- if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.stage.datacite.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(url)
+ if %r{\A(?:(http|https)://(dx\.)?(doi\.org|handle\.stage\.datacite\.org|handle\.test\.datacite\.org)/)?(doi:)?(10\.\d{4,5}/.+)\z}.match?(url)
uri = Addressable::URI.parse(url)
- uri.path.gsub(/^\//, '').downcase
+ uri.path.gsub(%r{^/}, '').downcase
end
end
def doi_as_url(doi)
"https://doi.org/#{doi}" if doi.present?
@@ -57,9 +57,9 @@
return nil if prefix.blank?
url = "https://doi.org/ra/#{prefix}"
result = Maremma.get(url)
- result.body.dig("data", 0, "RA")
+ result.body.dig('data', 0, 'RA')
end
end
end