Class: GOBL::Operations::ValidationResult

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • service_error (String)

Returns:



32
33
34
35
36
# File 'lib/gobl/operations/validation_result.rb', line 32

def self.from_service_error(service_error)
  message = service_error.match(SERVICE_ERROR_REGEX)[:msg]
  errors = message.split('; ')
  new errors
end

.validValidationResult

Builds a new ‘ValidationResult` object for a positive `validate` operation

Returns:



41
42
43
# File 'lib/gobl/operations/validation_result.rb', line 41

def self.valid
  new []
end

Instance Method Details

#errorsArray

The list of errors found in the GOBL structure

Returns:

  • (Array)


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

Returns:

  • (Boolean)


16
17
18
# File 'lib/gobl/operations/validation_result.rb', line 16

def valid?
  @errors.empty?
end