Class: Hyrax::OrcidValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/hyrax/orcid_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match(string) ⇒ Object



8
9
10
# File 'app/models/hyrax/orcid_validator.rb', line 8

def self.match(string)
  Regexp.new(orcid_regex).match(string) { |m| m[:orcid] }
end

Instance Method Details

#validate(record) ⇒ Object



3
4
5
6
# File 'app/models/hyrax/orcid_validator.rb', line 3

def validate(record)
  return if record.orcid.blank?
  record.errors.add(:orcid, 'must be a string of 19 characters, e.g., "0000-0000-0000-0000"') unless self.class.match(record.orcid)
end