Class: ExtractTtc::Models::ValidationResult
- Inherits:
-
Object
- Object
- ExtractTtc::Models::ValidationResult
- 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
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
-
#add_error(message) ⇒ ValidationResult
Add an error message to the result.
-
#initialize(valid: true, errors: []) ⇒ ValidationResult
constructor
Initialize a new validation result.
-
#invalid? ⇒ Boolean
Check if the validation failed.
-
#valid? ⇒ Boolean
Check if the validation passed.
Constructor Details
#initialize(valid: true, errors: []) ⇒ ValidationResult
Initialize a new validation result
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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/extract_ttc/models/validation_result.rb', line 13 def errors @errors end |
#valid ⇒ Object (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.
45 46 47 48 49 50 |
# File 'lib/extract_ttc/models/validation_result.rb', line 45 def add_error() self.class.new( valid: false, errors: @errors.dup << , ) end |
#invalid? ⇒ Boolean
Check if the validation failed
34 35 36 |
# File 'lib/extract_ttc/models/validation_result.rb', line 34 def invalid? !@valid end |
#valid? ⇒ Boolean
Check if the validation passed
27 28 29 |
# File 'lib/extract_ttc/models/validation_result.rb', line 27 def valid? @valid end |