Class: Hyrax::OrcidValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Hyrax::OrcidValidator
- Defined in:
- app/models/hyrax/orcid_validator.rb
Constant Summary collapse
- ORCID_REGEXP =
%r{^(?<prefix>https?://orcid.org/)?(?<orcid>\d{4}-\d{4}-\d{4}-\d{3}[\dX])/?$}.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extract_bare_orcid(from:) ⇒ Object
15 16 17 |
# File 'app/models/hyrax/orcid_validator.rb', line 15 def self.(from:) ORCID_REGEXP.match(from) { |m| m[:orcid] } end |
Instance Method Details
#validate(record) ⇒ Object
5 6 7 8 |
# File 'app/models/hyrax/orcid_validator.rb', line 5 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 ORCID_REGEXP.match?(record.orcid) end |