Class: DecisionAgent::Explainability::RuleTrace
- Inherits:
-
Object
- Object
- DecisionAgent::Explainability::RuleTrace
- Defined in:
- lib/decision_agent/explainability/rule_trace.rb
Overview
Represents the trace of a rule evaluation including all conditions
Instance Attribute Summary collapse
-
#condition_traces ⇒ Object
readonly
Returns the value of attribute condition_traces.
-
#decision ⇒ Object
readonly
Returns the value of attribute decision.
-
#matched ⇒ Object
readonly
Returns the value of attribute matched.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#rule_id ⇒ Object
readonly
Returns the value of attribute rule_id.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #failed_conditions ⇒ Object
-
#initialize(rule_id:, matched:, condition_traces: [], decision: nil, weight: nil, reason: nil) ⇒ RuleTrace
constructor
A new instance of RuleTrace.
- #passed_conditions ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(rule_id:, matched:, condition_traces: [], decision: nil, weight: nil, reason: nil) ⇒ RuleTrace
Returns a new instance of RuleTrace.
9 10 11 12 13 14 15 16 17 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 9 def initialize(rule_id:, matched:, condition_traces: [], decision: nil, weight: nil, reason: nil) @rule_id = rule_id.to_s.freeze @matched = matched @condition_traces = Array(condition_traces).freeze @decision = decision ? decision.to_s.freeze : nil @weight = weight @reason = reason ? reason.to_s.freeze : nil freeze end |
Instance Attribute Details
#condition_traces ⇒ Object (readonly)
Returns the value of attribute condition_traces.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def condition_traces @condition_traces end |
#decision ⇒ Object (readonly)
Returns the value of attribute decision.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def decision @decision end |
#matched ⇒ Object (readonly)
Returns the value of attribute matched.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def matched @matched end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def reason @reason end |
#rule_id ⇒ Object (readonly)
Returns the value of attribute rule_id.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def rule_id @rule_id end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
7 8 9 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7 def weight @weight end |
Instance Method Details
#failed_conditions ⇒ Object
23 24 25 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 23 def failed_conditions @condition_traces.select(&:failed?) end |
#passed_conditions ⇒ Object
19 20 21 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 19 def passed_conditions @condition_traces.select(&:passed?) end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/decision_agent/explainability/rule_trace.rb', line 27 def to_h { rule_id: @rule_id, matched: @matched, decision: @decision, weight: @weight, reason: @reason, condition_traces: @condition_traces.map(&:to_h), passed_conditions: passed_conditions.map(&:description), failed_conditions: failed_conditions.map(&:description) } end |