Class: Moab::VerificationResult
- Inherits:
-
Object
- Object
- Moab::VerificationResult
- Defined in:
- lib/moab/verification_result.rb
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
The result of evaluating the expression.
-
.verify_value(entity, expected, found) ⇒ VerificationResult
The result of comparing the expected and found values.
Instance Method Summary collapse
-
#initialize(entity) ⇒ VerificationResult
constructor
A new instance of VerificationResult.
-
#subentities_to_hash(verbose, level) ⇒ OrderedHash
The verification result of subentities serialized to a hash.
-
#to_hash(verbose = false, level = 0) ⇒ OrderedHash
The verification result serialized to a hash.
-
#to_json(verbose = false) ⇒ String
The verification result serialized to JSON.
Constructor Details
#initialize(entity) ⇒ VerificationResult
Returns a new instance of VerificationResult.
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
#details ⇒ Hash
Returns The details of the comparisons that were made.
14 15 16 |
# File 'lib/moab/verification_result.rb', line 14 def details @details end |
#entity ⇒ String
Returns The name of the entity that was verified.
8 9 10 |
# File 'lib/moab/verification_result.rb', line 8 def entity @entity end |
#subentities ⇒ Array<VerificationResult>
Returns 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 |
#verified ⇒ Boolean
Returns 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.
42 43 44 45 46 47 |
# File 'lib/moab/verification_result.rb', line 42 def self.verify_truth(entity,expression,details=nil) result = VerificationResult.new(entity.to_s) 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.
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) ⇒ OrderedHash
Returns The verification result of subentities serialized to a hash.
74 75 76 77 78 79 80 |
# File 'lib/moab/verification_result.rb', line 74 def subentities_to_hash(verbose,level) hash = OrderedHash.new @subentities.each do |s| hash[s.entity] = s.to_hash(verbose, level+1) end hash end |
#to_hash(verbose = false, level = 0) ⇒ OrderedHash
Returns The verification result serialized to a hash.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/moab/verification_result.rb', line 58 def to_hash(verbose=false,level=0) hash = OrderedHash.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.
51 52 53 |
# File 'lib/moab/verification_result.rb', line 51 def to_json(verbose=false) JSON.pretty_generate(to_hash(verbose)) end |