Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/orcid_client/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def initialize(doi:, orcid:, orcid_token:, **options)

SCHEMA = File.expand_path("../../../resources/record_#{API_VERSION}/work-#{API_VERSION}.xsd", __FILE__)

VERSION_OF_RELATION_TYPES = ["IsVersionOf", "HasVersion", "IsNewVersionOf", "IsPreviousVersionOf", "IsIdenticalTo"].freeze

# recognize given name. Can be loaded once as ::NameDetector, e.g. in a Rails initializer
def name_detector
@name_detector ||= defined?(::NameDetector) ? ::NameDetector : GenderDetector.new
Expand Down Expand Up @@ -76,6 +78,20 @@ def type
orcid_work_type(metadata.types["resourceTypeGeneral"], metadata.types["resourceType"])
end

def version_of_dois
Array.wrap(metadata.related_identifiers).filter_map do |related_identifier|
if related_identifier["relatedIdentifierType"] == "DOI" && VERSION_OF_RELATION_TYPES.include?(related_identifier["relationType"])
validate_doi(related_identifier["relatedIdentifier"])
end
end.compact.uniq
end

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
# remove non-printing whitespace and downcase
doi.delete("\u200B").downcase if doi.present?
end

def has_required_elements?
doi && contributors && title && container_title && publication_date
end
Expand Down Expand Up @@ -132,6 +148,9 @@ def insert_pub_date(xml)
def insert_ids(xml)
xml.send(:'common:external-ids') do
insert_id(xml, 'doi', doi, 'self')
version_of_dois.each do |version_of_doi|
insert_id(xml, 'doi', version_of_doi, 'version-of')
end
end
end

Expand Down
Loading
Loading