lib/bolognese/utils.rb in bolognese-0.4.3 vs lib/bolognese/utils.rb in bolognese-0.5
- old
+ new
@@ -1,15 +1,7 @@
module Bolognese
module Utils
- def normalize_orcid(orcid)
- orcid = validate_orcid(orcid)
- return nil unless orcid.present?
-
- # turn ORCID ID into URL
- "http://orcid.org/" + Addressable::URI.encode(orcid)
- end
-
def orcid_from_url(url)
Array(/\Ahttp:\/\/orcid\.org\/(.+)/.match(url)).last
end
def orcid_as_url(orcid)
@@ -50,16 +42,36 @@
else
nil
end
end
- def normalize_url(url)
- return nil unless url.present?
+ def find_provider(id)
+ id = normalize_id(id)
- normalize_doi(url) || PostRank::URI.clean(url)
+ if /\A(?:(http|https):\/\/(dx\.)?doi.org\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match(id)
+ get_doi_ra(id).fetch("id", nil)
+ elsif /\A(?:(http|https):\/\/orcid\.org\/)?(\d{4}-\d{4}-\d{4}-\d{3}[0-9X]+)\z/.match(id)
+ "orcid"
+ else
+ "schema_org"
+ end
end
+ def normalize_id(id)
+ return nil unless id.present?
+
+ normalize_doi(id) || PostRank::URI.clean(id)
+ end
+
+ def normalize_orcid(orcid)
+ orcid = validate_orcid(orcid)
+ return nil unless orcid.present?
+
+ # turn ORCID ID into URL
+ "http://orcid.org/" + Addressable::URI.encode(orcid)
+ end
+
def normalize_ids(list)
- Array.wrap(list).map { |url| url.merge("@id" => normalize_url(url["@id"])) }
+ Array.wrap(list).map { |url| url.merge("@id" => normalize_id(url["@id"])) }
end
end
end