Class: Cocina::Models::Validators::DateTimeValidator
- Inherits:
-
Object
- Object
- Cocina::Models::Validators::DateTimeValidator
- Defined in:
- lib/cocina/models/validators/date_time_validator.rb
Overview
Validates that dates of known types are type-valid
Constant Summary collapse
- VALIDATABLE_TYPES =
%w[edtf iso8601 w3cdtf].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ DateTimeValidator
constructor
A new instance of DateTimeValidator.
- #validate ⇒ Object
Constructor Details
#initialize(attributes) ⇒ DateTimeValidator
Returns a new instance of DateTimeValidator.
17 18 19 |
# File 'lib/cocina/models/validators/date_time_validator.rb', line 17 def initialize(attributes) @attributes = attributes end |
Class Method Details
.validate(_clazz, attributes) ⇒ Object
13 14 15 |
# File 'lib/cocina/models/validators/date_time_validator.rb', line 13 def self.validate(_clazz, attributes) new(attributes).validate end |
Instance Method Details
#validate ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/cocina/models/validators/date_time_validator.rb', line 21 def validate return unless meets_preconditions? return if invalid_dates.empty? raise ValidationError, "Invalid date(s) for #{druid}: #{invalid_dates}" end |