Class: Dragnet::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/dragnet/validator.rb

Overview

Validates a set of Manual Test Record files. That means, checking that they can be read, that they are valid YAML files, that they have the expected keys and that these keys have sensible values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files:, path:, logger:) ⇒ Validator

Creates a new instance of the class.

Parameters:

  • files (Array<Pathname>)

    An array with the MTR files to validate.

  • path (Pathname)

    The path where the MTR files are located.

  • logger (#info, #error)

    A logger object to use for output.



20
21
22
23
24
# File 'lib/dragnet/validator.rb', line 20

def initialize(files:, path:, logger:)
  @files = files
  @path = path
  @logger = logger
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/dragnet/validator.rb', line 14

def errors
  @errors
end

#filesObject (readonly)

Returns the value of attribute files.



14
15
16
# File 'lib/dragnet/validator.rb', line 14

def files
  @files
end

#loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/dragnet/validator.rb', line 14

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/dragnet/validator.rb', line 14

def path
  @path
end

#valid_filesObject (readonly)

Returns the value of attribute valid_files.



14
15
16
# File 'lib/dragnet/validator.rb', line 14

def valid_files
  @valid_files
end

Instance Method Details

#validateArray<Dragnet::TestRecord>

Validates the given files.

Returns:

  • (Array<Dragnet::TestRecord>)

    An array of TestRecords, one for each valid MTR file (invalid files will be added to the errors array). The returned hash has the following structure:



30
31
32
33
34
35
# File 'lib/dragnet/validator.rb', line 30

def validate
  logger.info('Validating MTR Files...')

  @errors = []
  @valid_files = files.map { |file| validate_file(file) }.compact
end