Class: Dragnet::Validators::Fields::ResultValidator

Inherits:
FieldValidator show all
Defined in:
lib/dragnet/validators/fields/result_validator.rb

Overview

Validates the result field of an MTR Record

Constant Summary collapse

VALID_RESULTS =
%w[passed failed].freeze

Instance Method Summary collapse

Instance Method Details

#validate(key, value) ⇒ String

Validates the MTR's result

Parameters:

  • key (String)

    The name of the key

  • value (Object)

    The value of the key

Returns:

  • (String)

    The downcase version of the result field.

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dragnet/validators/fields/result_validator.rb', line 18

def validate(key, value)
  validate_presence(key, value)
  validate_type(key, value, String)

  value = value.downcase
  return value if VALID_RESULTS.include?(value)

  validation_error(
    "Invalid value for key result: '#{value}'. "\
    "Valid values are #{VALID_RESULTS.join(', ')}"
  )
end