Class: Dragnet::Validators::DataValidator
- Defined in:
- lib/dragnet/validators/data_validator.rb
Overview
Validates the data (key-value pairs) inside an MTR file. Verifies the structure, the required keys and their types.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#source_file ⇒ Object
readonly
Returns the value of attribute source_file.
Instance Method Summary collapse
-
#initialize(data, source_file) ⇒ DataValidator
constructor
Creates a new instance of the class.
-
#validate ⇒ Dragnet::TestRecord
Validates the given data.
Constructor Details
#initialize(data, source_file) ⇒ DataValidator
Creates a new instance of the class
20 21 22 23 |
# File 'lib/dragnet/validators/data_validator.rb', line 20 def initialize(data, source_file) @data = data @source_file = source_file end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/dragnet/validators/data_validator.rb', line 14 def data @data end |
#source_file ⇒ Object (readonly)
Returns the value of attribute source_file.
14 15 16 |
# File 'lib/dragnet/validators/data_validator.rb', line 14 def source_file @source_file end |
Instance Method Details
#validate ⇒ Dragnet::TestRecord
Validates the given data
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dragnet/validators/data_validator.rb', line 31 def validate yaml_format_error("Incompatible data structure. Expecting a Hash, got a #{data.class}") unless data.is_a?(Hash) data.deep_symbolize_keys! # A call to chomp for strings is needed because the following YAML # syntax: # # findings: > # no findings # # causes the string values to end with a newline ("\n"): data.transform_values! { |value| value.is_a?(String) ? value.chomp : value } test_record = create_mtr(data) validate_mtr(test_record) end |