Class: ExtractTtc::Models::ValidationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/extract_ttc/models/validation_result.rb

Overview

Represents the result of a validation operation

This model encapsulates the outcome of validating files, headers, or other data structures, including whether the validation passed and any error messages generated during validation.

This is an immutable value object with methods to query validity status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid: true, errors: []) ⇒ ValidationResult

Initialize a new validation result

Parameters:

  • valid (Boolean) (defaults to: true)

    Whether the validation passed

  • errors (Array<String>) (defaults to: [])

    Array of error messages (empty if valid)



19
20
21
22
# File 'lib/extract_ttc/models/validation_result.rb', line 19

def initialize(valid: true, errors: [])
  @valid = valid
  @errors = errors.freeze
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



13
14
15
# File 'lib/extract_ttc/models/validation_result.rb', line 13

def errors
  @errors
end

#validObject (readonly)

Returns the value of attribute valid.



13
14
15
# File 'lib/extract_ttc/models/validation_result.rb', line 13

def valid
  @valid
end

Instance Method Details

#add_error(message) ⇒ ValidationResult

Add an error message to the result

This creates a new ValidationResult with the error added, as the object is immutable.

Parameters:

  • message (String)

    The error message to add

Returns:



45
46
47
48
49
50
# File 'lib/extract_ttc/models/validation_result.rb', line 45

def add_error(message)
  self.class.new(
    valid: false,
    errors: @errors.dup << message,
  )
end

#invalid?Boolean

Check if the validation failed

Returns:

  • (Boolean)

    true if invalid, false otherwise



34
35
36
# File 'lib/extract_ttc/models/validation_result.rb', line 34

def invalid?
  !@valid
end

#valid?Boolean

Check if the validation passed

Returns:

  • (Boolean)

    true if valid, false otherwise



27
28
29
# File 'lib/extract_ttc/models/validation_result.rb', line 27

def valid?
  @valid
end