class Identifiers::ORCID
Constants
- REGEXP
Public Class Methods
calculate_digit(str)
click to toggle source
# File lib/identifiers/orcid.rb, line 16 def self.calculate_digit(str) return unless str =~ REGEXP base_digits = str.chop.tr('-', '') total = 0 base_digits.each_char { |c| total = (total + Integer(c)) * 2 } remainder = total % 11 result = (12 - remainder) % 11 result == 10 ? 'X' : result.to_s end
extract(str)
click to toggle source
# File lib/identifiers/orcid.rb, line 5 def self.extract(str) str.to_s.scan(REGEXP).select { |orcid| valid?(orcid) }.map(&:upcase) end
valid?(str)
click to toggle source
# File lib/identifiers/orcid.rb, line 9 def self.valid?(str) digit = calculate_digit(str) return false unless digit digit == str[-1].upcase end