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

Version Path
hyrax-2.9.6 app/models/hyrax/orcid_validator.rb
hyrax-2.9.5 app/models/hyrax/orcid_validator.rb
hyrax-2.9.4 app/models/hyrax/orcid_validator.rb
hyrax-2.9.3 app/models/hyrax/orcid_validator.rb
hyrax-2.9.2 app/models/hyrax/orcid_validator.rb
hyrax-2.9.1 app/models/hyrax/orcid_validator.rb
hyrax-2.9.0 app/models/hyrax/orcid_validator.rb
hyrax-2.8.0 app/models/hyrax/orcid_validator.rb
hyrax-2.7.2 app/models/hyrax/orcid_validator.rb
hyrax-2.7.1 app/models/hyrax/orcid_validator.rb
hyrax-2.7.0 app/models/hyrax/orcid_validator.rb
hyrax-2.6.0 app/models/hyrax/orcid_validator.rb
hyrax-3.0.0.pre.rc1 app/models/hyrax/orcid_validator.rb
hyrax-3.0.0.pre.beta3 app/models/hyrax/orcid_validator.rb
hyrax-2.5.1 app/models/hyrax/orcid_validator.rb
hyrax-2.5.0 app/models/hyrax/orcid_validator.rb
hyrax-3.0.0.pre.beta2 app/models/hyrax/orcid_validator.rb
hyrax-2.4.1 app/models/hyrax/orcid_validator.rb
hyrax-3.0.0.pre.beta1 app/models/hyrax/orcid_validator.rb
hyrax-2.4.0 app/models/hyrax/orcid_validator.rb