Class: Moab::VerificationResult

Inherits:
Object
  • Object
show all
Defined in:
lib/moab/verification_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ VerificationResult

Returns a new instance of VerificationResult.

Parameters:

  • entity (Object)

    The name of the entity being verified



20
21
22
23
24
25
# File 'lib/moab/verification_result.rb', line 20

def initialize(entity)
  @entity = entity
  @verified = false
  @details = nil
  @subentities = Array.new
end

Instance Attribute Details

#detailsHash

Returns The details of the comparisons that were made.

Returns:

  • (Hash)

    The details of the comparisons that were made



14
15
16
# File 'lib/moab/verification_result.rb', line 14

def details
  @details
end

#entityString

Returns The name of the entity that was verified.

Returns:

  • (String)

    The name of the entity that was verified



8
9
10
# File 'lib/moab/verification_result.rb', line 8

def entity
  @entity
end

#subentitiesArray<VerificationResult>

Returns The subentities, if any, on which this verification is based.

Returns:

  • (Array<VerificationResult>)

    The subentities, if any, on which this verification is based



17
18
19
# File 'lib/moab/verification_result.rb', line 17

def subentities
  @subentities
end

#verifiedBoolean

Returns The true/false outcome of the verification.

Returns:

  • (Boolean)

    The true/false outcome of the verification



11
12
13
# File 'lib/moab/verification_result.rb', line 11

def verified
  @verified
end

Class Method Details

.verify_truth(entity, expression, details = nil) ⇒ VerificationResult

Returns The result of evaluating the expression.

Parameters:

  • entity (Symbol)

    The name of the entity being verified

  • expression (Object)

    The expression that will be evaluated as true or false

  • details (Object) (defaults to: nil)

    optional details that could be reported

Returns:



42
43
44
45
46
47
48
# File 'lib/moab/verification_result.rb', line 42

def self.verify_truth(entity,expression,details=nil)
  result = VerificationResult.new(entity.to_s)
  # TODO: add expression.empty?
  result.verified = !(expression.nil? or (expression == false))
  result.details = details
  result
end

.verify_value(entity, expected, found) ⇒ VerificationResult

Returns The result of comparing the expected and found values.

Parameters:

  • entity (Symbol)

    The name of the entity being verified

  • expected (Object)

    The expected value

  • found (Object)

    The found value

Returns:



31
32
33
34
35
36
# File 'lib/moab/verification_result.rb', line 31

def self.verify_value(entity, expected, found)
  result = VerificationResult.new(entity.to_s)
  result.verified = (expected == found)
  result.details = {'expected' => expected, 'found' => found}
  result
end

Instance Method Details

#subentities_to_hash(verbose, level) ⇒ Hash

Returns The verification result of subentities serialized to a hash.

Parameters:

  • verbose (Boolean)

    If true, always provide all details of the verification

  • level (Integer)

    Used to increment the depth of recursion

Returns:

  • (Hash)

    The verification result of subentities serialized to a hash



75
76
77
78
79
80
81
# File 'lib/moab/verification_result.rb', line 75

def subentities_to_hash(verbose,level)
  hash = Hash.new
  @subentities.each do |s|
   hash[s.entity] = s.to_hash(verbose, level+1)
  end
  hash
end

#to_hash(verbose = false, level = 0) ⇒ Hash

Returns The verification result serialized to a hash.

Parameters:

  • verbose (Boolean) (defaults to: false)

    If true, always provide all details of the verification

  • level (Integer) (defaults to: 0)

    Used to test the depth of recursion

Returns:

  • (Hash)

    The verification result serialized to a hash



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/moab/verification_result.rb', line 59

def to_hash(verbose=false,level=0)
  hash = Hash.new
  hash['verified'] = @verified
  if (verbose or @verified == false)
    hash['details'] = @details ? @details : subentities_to_hash(verbose,level)
  end
  if level > 0
    hash
  else
    {@entity => hash}
  end
end

#to_json(verbose = false) ⇒ String

Returns The verification result serialized to JSON.

Parameters:

  • verbose (Boolean) (defaults to: false)

    If true, always provide all details of the verification

Returns:

  • (String)

    The verification result serialized to JSON



52
53
54
# File 'lib/moab/verification_result.rb', line 52

def to_json(verbose=false)
  JSON.pretty_generate(to_hash(verbose))
end