Sha256: ee5761dc4295d51349f0979afcd60ec1a98fc078948b168677c9f6ad5cac8093
Contents?: true
Size: 528 Bytes
Versions: 44
Compression:
Stored size: 528 Bytes
Contents
module Hyrax class OrcidValidator < ActiveModel::Validator 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 def self.match(string) Regexp.new(orcid_regex).match(string) { |m| m[:orcid] } end def self.orcid_regex '^(?<prefix>https?://orcid.org/)?(?<orcid>\d{4}-\d{4}-\d{4}-\d{3}[\dX])/?$' end private_class_method :orcid_regex end end
Version data entries
44 entries across 44 versions & 1 rubygems