Class: Dragnet::Validators::Fields::IDValidator

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

Overview

Validates the ID Field for Manual Test Records

Instance Method Summary collapse

Instance Method Details

#validate(key, value) ⇒ Object

Validates the Requirement ID(s) of the MTR

Parameters:

  • key (String)

    The name of the key

  • value (Object)

    The value of the key

Raises:

  • (Dragnet::Errors::ValidationError)

    If the Requirement ID(s) are missing, they are not a String or an Array of Strings if they contain a disallowed character or (in the case of an Array) any of its elements is not a String.



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

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

  if value.is_a?(String)
    match = value.match(/,|\s/)
    return unless match

    validation_error(
      "Disallowed character '#{match}' found in the value for key #{key}. "\
      'To use multiple requirement IDs please put them into an array'
    )
  else
    validate_array_types(key, value, String)
  end
end