Class: Cocina::Models::Validators::DescriptionValuesValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/validators/description_values_validator.rb

Overview

Validates that there is only one of value, groupedValue, structuredValue, or parallelValue.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz, attributes) ⇒ DescriptionValuesValidator

Returns a new instance of DescriptionValuesValidator.



12
13
14
15
16
17
18
# File 'lib/cocina/models/validators/description_values_validator.rb', line 12

def initialize(clazz, attributes)
  @clazz = clazz
  @attributes = attributes
  @error_paths_multiple = []
  @error_paths_blank = []
  @error_paths_missing_title_type = []
end

Class Method Details

.validate(clazz, attributes) ⇒ Object



8
9
10
# File 'lib/cocina/models/validators/description_values_validator.rb', line 8

def self.validate(clazz, attributes)
  new(clazz, attributes).validate
end

Instance Method Details

#validateObject

Raises:



20
21
22
23
24
25
26
27
28
# File 'lib/cocina/models/validators/description_values_validator.rb', line 20

def validate
  return unless meets_preconditions?

  validate_obj(attributes, [])

  raise ValidationError, "Multiple value, groupedValue, structuredValue, and parallelValue in description: #{error_paths_multiple.join(', ')}" unless error_paths_multiple.empty?
  raise ValidationError, "Blank value in description: #{error_paths_blank.join(', ')}" unless error_paths_blank.empty?
  raise ValidationError, "Missing type for value in description: #{error_paths_missing_title_type.join(', ')}" unless error_paths_missing_title_type.empty?
end