class Moab::VerificationResult
A recursive “Tree” type object for verifications
Attributes
@return [Hash] The details of the comparisons that were made
@return [String] The name of the entity that was verified
@return [Array<VerificationResult>] The subentities, if any, on which this verification is based
@return [Boolean] The true/false outcome of the verification
Public Class Methods
@param entity [#to_s] The name of the entity being verified @param verified [Boolean] @param details [Hash]
# File lib/moab/verification_result.rb, line 21 def initialize(entity, verified = false, details = nil) @entity = entity.to_s # force to string @verified = !!verified # rubocop:disable Style/DoubleNegation @details = details @subentities = [] end
@deprecated Just use the constructor @param entity [#to_s] The name of the entity being verified @param expression [Object] The expression that will be evaluated as true or false @param details [Object] optional details that could be reported @return [VerificationResult] The result of evaluating the expression
# File lib/moab/verification_result.rb, line 42 def self.verify_truth(entity, expression, details = nil) new(entity, expression, details) end
@param entity [#to_s] The name of the entity being verified @param expected [Object] The expected value @param found [Object] The found value @return [VerificationResult] The result of comparing the expected and found values
# File lib/moab/verification_result.rb, line 32 def self.verify_value(entity, expected, found) details = { 'expected' => expected, 'found' => found } new(entity, (expected == found), details) end
Public Instance Methods
@param verbose [Boolean] If true, always provide all details of the verification @param level [Integer] Used to test the depth of recursion @return [Hash] The verification result serialized to a hash
# File lib/moab/verification_result.rb, line 55 def to_hash(verbose = false, level = 0) hash = { 'verified' => verified } hash['details'] = details || subentities_to_hash(verbose, level) if verbose || !verified return hash if level > 0 { entity => hash } end
@param verbose [Boolean] If true, always provide all details of the verification @return [String] The verification result serialized to JSON
# File lib/moab/verification_result.rb, line 48 def to_json(verbose = false) JSON.pretty_generate(to_hash(verbose)) end
Private Instance Methods
@param verbose [Boolean] If true, always provide all details of the verification @param level [Integer] Used to increment the depth of recursion @return [Hash] The verification result of subentities serialized to a hash
# File lib/moab/verification_result.rb, line 68 def subentities_to_hash(verbose, level) subentities.to_h { |s| [s.entity, s.to_hash(verbose, level + 1)] } end