Class: Dina::PersistentIdentifier
- Inherits:
-
Object
- Object
- Dina::PersistentIdentifier
- Defined in:
- lib/dina/utils/identifier.rb
Class Method Summary collapse
- .extract_orcid_regex ⇒ Object
- .extract_wiki_regex ⇒ Object
- .is_doi_regex ⇒ Object
- .is_orcid_regex ⇒ Object
- .is_uuid_regex ⇒ Object
- .is_wiki_regex ⇒ Object
- .orcid_valid_checksum(orcid_string) ⇒ Object
Class Method Details
.extract_orcid_regex ⇒ Object
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_regex ⇒ Object
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_regex ⇒ Object
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_regex ⇒ Object
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_regex ⇒ Object
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_regex ⇒ Object
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 |