Class: Moab::VerificationResult
- Inherits:
-
Object
- Object
- Moab::VerificationResult
- Defined in:
- lib/moab/verification_result.rb
Overview
A recursive “Tree” type object for verifications
Instance Attribute Summary collapse
-
#details ⇒ Hash
The details of the comparisons that were made.
-
#entity ⇒ String
The name of the entity that was verified.
-
#subentities ⇒ Array<VerificationResult>
The subentities, if any, on which this verification is based.
-
#verified ⇒ Boolean
The true/false outcome of the verification.
Class Method Summary collapse
-
.verify_truth(entity, expression, details = nil) ⇒ VerificationResult
deprecated
Deprecated.
Just use the constructor
-
.verify_value(entity, expected, found) ⇒ VerificationResult
The result of comparing the expected and found values.
Instance Method Summary collapse
-
#initialize(entity, verified = false, details = nil) ⇒ VerificationResult
constructor
A new instance of VerificationResult.
-
#to_hash(verbose = false, level = 0) ⇒ Hash
The verification result serialized to a hash.
-
#to_json(verbose = false) ⇒ String
The verification result serialized to JSON.
Constructor Details
#initialize(entity, verified = false, details = nil) ⇒ VerificationResult
21 22 23 24 25 26 |
# 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 |
Instance Attribute Details
#details ⇒ Hash
13 14 15 |
# File 'lib/moab/verification_result.rb', line 13 def details @details end |
#entity ⇒ String
7 8 9 |
# File 'lib/moab/verification_result.rb', line 7 def entity @entity end |
#subentities ⇒ Array<VerificationResult>
16 17 18 |
# File 'lib/moab/verification_result.rb', line 16 def subentities @subentities end |
#verified ⇒ Boolean
10 11 12 |
# File 'lib/moab/verification_result.rb', line 10 def verified @verified end |
Class Method Details
.verify_truth(entity, expression, details = nil) ⇒ VerificationResult
Deprecated.
Just use the constructor
Returns The result of evaluating the expression.
42 43 44 |
# 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) ⇒ VerificationResult
32 33 34 35 |
# 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) # rubocop:disable Style/RedundantParentheses end |
Instance Method Details
#to_hash(verbose = false, level = 0) ⇒ Hash
55 56 57 58 59 60 61 |
# 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) ⇒ String
48 49 50 |
# File 'lib/moab/verification_result.rb', line 48 def to_json(verbose = false) JSON.pretty_generate(to_hash(verbose)) end |