Class: Cocina::Models::Validators::DescriptionLanguageCodeVisitorValidator

Inherits:
BaseDescriptionVisitorValidator show all
Defined in:
lib/cocina/models/validators/description_language_code_visitor_validator.rb

Overview

Validates language.code values against searchworks_languages from cocina_display gem plus mul, und, zxx.

Constant Summary collapse

EXTRA_VALID_CODES =
%w[mul und zxx].freeze

Instance Method Summary collapse

Methods inherited from BaseDescriptionVisitorValidator

#path_to_s, #visit_array, #visit_obj

Instance Method Details

#validate!Object

Raises:



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

def validate!
  return if error_paths.empty?

  raise ValidationError, "Unrecognized language codes in description: #{error_paths.join(', ')}"
end

#visit_hash(hash:, path:) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/cocina/models/validators/description_language_code_visitor_validator.rb', line 18

def visit_hash(hash:, path:)
  return unless language_path?(path)

  code = hash[:code]
  return unless code

  error_paths << "#{path_to_s(path)}.code (#{code})" unless valid_codes.include?(code)
end