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
Returns a new instance of 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 = Array.new end |
Instance Attribute Details
#details ⇒ Hash
Returns The details of the comparisons that were made.
13 14 15 |
# File 'lib/moab/verification_result.rb', line 13 def details @details end |
#entity ⇒ String
Returns The name of the entity that was verified.
7 8 9 |
# File 'lib/moab/verification_result.rb', line 7 def entity @entity end |
#subentities ⇒ Array<VerificationResult>
Returns The subentities, if any, on which this verification is based.
16 17 18 |
# File 'lib/moab/verification_result.rb', line 16 def subentities @subentities end |
#verified ⇒ Boolean
Returns The true/false outcome of the verification.
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
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
Returns The result of comparing the expected and found values.
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) end |
Instance Method Details
#to_hash(verbose = false, level = 0) ⇒ Hash
Returns The verification result serialized to a hash.
55 56 57 58 59 60 61 62 |
# File 'lib/moab/verification_result.rb', line 55 def to_hash(verbose = false, level = 0) hash = { 'verified' => verified } if verbose || !verified hash['details'] = details || subentities_to_hash(verbose, level) end return hash if level > 0 { entity => hash } end |
#to_json(verbose = false) ⇒ String
Returns The verification result serialized to JSON.
48 49 50 |
# File 'lib/moab/verification_result.rb', line 48 def to_json(verbose = false) JSON.pretty_generate(to_hash(verbose)) end |