Class: Dina::PersistentIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/dina/utils/identifier.rb

Class Method Summary collapse

Class Method Details

.extract_orcid_regexObject



59
60
61
# File 'lib/dina/utils/identifier.rb', line 59

def extract_orcid_regex
  /(?<=orcid\.org\/)(\d{4}-){3}\d{3}[0-9X]{1}/
end

.extract_wiki_regexObject



63
64
65
# File 'lib/dina/utils/identifier.rb', line 63

def extract_wiki_regex
  /(?:wikidata\.org\/(entity|wiki)\/)\K(Q[0-9]{1,})/
end

.is_doi_regexObject



42
43
44
# File 'lib/dina/utils/identifier.rb', line 42

def is_doi_regex
  /^10.\d{4,9}\/[-._;()\/:<>A-Z0-9]+$/i
end

.is_orcid_regexObject



34
35
36
# File 'lib/dina/utils/identifier.rb', line 34

def is_orcid_regex
  /^0000-000(1-[5-9]|2-[0-9]|3-[0-4])\d{3}-\d{3}[\dX]$/
end

.is_uuid_regexObject



46
47
48
# File 'lib/dina/utils/identifier.rb', line 46

def is_uuid_regex
  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
end

.is_wiki_regexObject



38
39
40
# File 'lib/dina/utils/identifier.rb', line 38

def is_wiki_regex
  /^Q[0-9]{1,}$/
end

.orcid_valid_checksum(orcid_string) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/dina/utils/identifier.rb', line 50

def orcid_valid_checksum(orcid_string)
  parts = orcid_string.scan(/[0-9X]/)
  mod = parts[0..14].map(&:to_i)
                    .inject { |sum, n| (sum + n)*2 }
                    .modulo(11)
  result = (12 - mod) % 11
  parts.last == ((result == 10) ? "X" : result.to_s)
end