app/graphql/types/base_object.rb
# frozen_string_literal: true
class BaseObject < GraphQL::Schema::Object
include ApolloFederation::Object
field_class BaseField
def doi_from_url(url)
if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(/^\//, "").downcase
end
end
def orcid_from_url(url)
if /\A(?:(http|https):\/\/(orcid.org)\/)(.+)\z/.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(/^\//, "").downcase
end
end
end