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
- .extract_bare_orcid(from:) ⇒ Object
- .match(string) ⇒ Object deprecated Deprecated.
Instance Method Summary collapse
Class Method Details
.extract_bare_orcid(from:) ⇒ Object
21 22 23 |
# File 'app/models/hyrax/orcid_validator.rb', line 21 def self.(from:) ORCID_REGEXP.match(from) { |m| m[:orcid] } end |
.match(string) ⇒ Object
Deprecated.
11 12 13 14 |
# File 'app/models/hyrax/orcid_validator.rb', line 11 def self.match(string) Deprecation.warn "Use 'Hyrax::OrcidValidator.extract_bare_orcid(from:)'" (from: string) 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 |