Class: RailsXapi::Validators::LanguageMapValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/models/rails_xapi/validators/language_map_validator.rb

Constant Summary collapse

LANGUAGE_MAP_REGEX =
/\A[a-z]{2}(-[A-Z]{2})?\z/

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/rails_xapi/validators/language_map_validator.rb', line 8

def validate(record)
  attributes_to_validate = options[:attributes] || []

  attributes_to_validate.each do |attribute|
    next unless record.respond_to?(attribute)

    raw_value = record.public_send(attribute)
    next unless raw_value.present?

    validate_language_map_keys(record, attribute, raw_value)
  end
end