class Moab::VerificationResult

A recursive “Tree” type object for verifications

Attributes

details[RW]

@return [Hash] The details of the comparisons that were made

entity[RW]

@return [String] The name of the entity that was verified

subentities[RW]

@return [Array<VerificationResult>] The subentities, if any, on which this verification is based

verified[RW]

@return [Boolean] The true/false outcome of the verification

Public Class Methods

new(entity, verified = false, details = nil) click to toggle source

@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
verify_truth(entity, expression, details = nil) click to toggle source

@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
verify_value(entity, expected, found) click to toggle source

@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

to_hash(verbose = false, level = 0) click to toggle source

@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
to_json(verbose = false) click to toggle source

@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

subentities_to_hash(verbose, level) click to toggle source

@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