Class: Igniter::Extensions::Contracts::Differential::Report
- Inherits:
-
Object
- Object
- Igniter::Extensions::Contracts::Differential::Report
- Defined in:
- lib/igniter/extensions/contracts/differential/report.rb
Instance Attribute Summary collapse
-
#candidate_error ⇒ Object
readonly
Returns the value of attribute candidate_error.
-
#candidate_name ⇒ Object
readonly
Returns the value of attribute candidate_name.
-
#candidate_only ⇒ Object
readonly
Returns the value of attribute candidate_only.
-
#candidate_outputs ⇒ Object
readonly
Returns the value of attribute candidate_outputs.
-
#divergences ⇒ Object
readonly
Returns the value of attribute divergences.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#primary_error ⇒ Object
readonly
Returns the value of attribute primary_error.
-
#primary_name ⇒ Object
readonly
Returns the value of attribute primary_name.
-
#primary_only ⇒ Object
readonly
Returns the value of attribute primary_only.
-
#primary_outputs ⇒ Object
readonly
Returns the value of attribute primary_outputs.
Instance Method Summary collapse
- #explain ⇒ Object (also: #to_s)
-
#initialize(primary_name:, candidate_name:, inputs:, primary_outputs:, candidate_outputs:, divergences:, primary_only:, candidate_only:, primary_error: nil, candidate_error: nil) ⇒ Report
constructor
A new instance of Report.
- #match? ⇒ Boolean
- #summary ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(primary_name:, candidate_name:, inputs:, primary_outputs:, candidate_outputs:, divergences:, primary_only:, candidate_only:, primary_error: nil, candidate_error: nil) ⇒ Report
Returns a new instance of Report.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 13 def initialize( primary_name:, candidate_name:, inputs:, primary_outputs:, candidate_outputs:, divergences:, primary_only:, candidate_only:, primary_error: nil, candidate_error: nil ) @primary_name = primary_name.to_s @candidate_name = candidate_name.to_s @inputs = inputs.transform_keys(&:to_sym).freeze @primary_outputs = primary_outputs.transform_keys(&:to_sym).freeze @candidate_outputs = candidate_outputs.transform_keys(&:to_sym).freeze @divergences = divergences.freeze @primary_only = primary_only.transform_keys(&:to_sym).freeze @candidate_only = candidate_only.transform_keys(&:to_sym).freeze @primary_error = primary_error&.freeze @candidate_error = candidate_error&.freeze freeze end |
Instance Attribute Details
#candidate_error ⇒ Object (readonly)
Returns the value of attribute candidate_error.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def candidate_error @candidate_error end |
#candidate_name ⇒ Object (readonly)
Returns the value of attribute candidate_name.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def candidate_name @candidate_name end |
#candidate_only ⇒ Object (readonly)
Returns the value of attribute candidate_only.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def candidate_only @candidate_only end |
#candidate_outputs ⇒ Object (readonly)
Returns the value of attribute candidate_outputs.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def candidate_outputs @candidate_outputs end |
#divergences ⇒ Object (readonly)
Returns the value of attribute divergences.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def divergences @divergences end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def inputs @inputs end |
#primary_error ⇒ Object (readonly)
Returns the value of attribute primary_error.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def primary_error @primary_error end |
#primary_name ⇒ Object (readonly)
Returns the value of attribute primary_name.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def primary_name @primary_name end |
#primary_only ⇒ Object (readonly)
Returns the value of attribute primary_only.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def primary_only @primary_only end |
#primary_outputs ⇒ Object (readonly)
Returns the value of attribute primary_outputs.
8 9 10 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 8 def primary_outputs @primary_outputs end |
Instance Method Details
#explain ⇒ Object Also known as: to_s
58 59 60 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 58 def explain Formatter.format(self) end |
#match? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 38 def match? divergences.empty? && primary_only.empty? && candidate_only.empty? && primary_error.nil? && candidate_error.nil? end |
#summary ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 46 def summary return "match" if match? parts = [] parts << "#{divergences.size} value(s) differ" if divergences.any? parts << "#{primary_only.size} output(s) only in primary" if primary_only.any? parts << "#{candidate_only.size} output(s) only in candidate" if candidate_only.any? parts << "candidate error: #{candidate_error.fetch(:message)}" if candidate_error parts << "primary error: #{primary_error.fetch(:message)}" if primary_error "diverged - #{parts.join(", ")}" end |
#to_h ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/igniter/extensions/contracts/differential/report.rb', line 64 def to_h { primary: primary_name, candidate: candidate_name, inputs: inputs, match: match?, primary_outputs: primary_outputs, candidate_outputs: candidate_outputs, divergences: divergences.map(&:to_h), primary_only: primary_only, candidate_only: candidate_only, primary_error: primary_error, candidate_error: candidate_error } end |