Class: GOBL::Operations::ValidationResult
- Inherits:
-
Object
- Object
- GOBL::Operations::ValidationResult
- Defined in:
- lib/gobl/operations/validation_result.rb
Overview
The result of a GOBL validation over a GOBL structure
Constant Summary collapse
- SERVICE_ERROR_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/^code=(?<code>\d+), message=(?<msg>.+)$/.freeze
Class Method Summary collapse
-
.from_service_error(service_error) ⇒ ValidationResult
Builds a new ‘ValidationResult` object resulted from parsing the service error response given as a parameter.
-
.valid ⇒ ValidationResult
Builds a new ‘ValidationResult` object for a positive `validate` operation.
Instance Method Summary collapse
-
#errors ⇒ Array
The list of errors found in the GOBL structure.
-
#initialize(errors) ⇒ ValidationResult
constructor
A new instance of ValidationResult.
-
#valid? ⇒ Boolean
Whether the GOBL structure were valid or not.
Constructor Details
#initialize(errors) ⇒ ValidationResult
Returns a new instance of ValidationResult.
9 10 11 |
# File 'lib/gobl/operations/validation_result.rb', line 9 def initialize(errors) @errors = errors end |
Class Method Details
.from_service_error(service_error) ⇒ ValidationResult
Builds a new ‘ValidationResult` object resulted from parsing the service
error response given as a parameter
32 33 34 35 36 |
# File 'lib/gobl/operations/validation_result.rb', line 32 def self.from_service_error(service_error) = service_error.match(SERVICE_ERROR_REGEX)[:msg] errors = .split('; ') new errors end |
.valid ⇒ ValidationResult
Builds a new ‘ValidationResult` object for a positive `validate` operation
41 42 43 |
# File 'lib/gobl/operations/validation_result.rb', line 41 def self.valid new [] end |
Instance Method Details
#errors ⇒ Array
The list of errors found in the GOBL structure
23 24 25 |
# File 'lib/gobl/operations/validation_result.rb', line 23 def errors @errors || [] end |
#valid? ⇒ Boolean
Whether the GOBL structure were valid or not
16 17 18 |
# File 'lib/gobl/operations/validation_result.rb', line 16 def valid? @errors.empty? end |