Class: DecisionAgent::Explainability::RuleTrace

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/explainability/rule_trace.rb

Overview

Represents the trace of a rule evaluation including all conditions

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tracesObject (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

#decisionObject (readonly)

Returns the value of attribute decision.



7
8
9
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7

def decision
  @decision
end

#matchedObject (readonly)

Returns the value of attribute matched.



7
8
9
# File 'lib/decision_agent/explainability/rule_trace.rb', line 7

def matched
  @matched
end

#reasonObject (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_idObject (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

#weightObject (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_conditionsObject



23
24
25
# File 'lib/decision_agent/explainability/rule_trace.rb', line 23

def failed_conditions
  @condition_traces.select(&:failed?)
end

#passed_conditionsObject



19
20
21
# File 'lib/decision_agent/explainability/rule_trace.rb', line 19

def passed_conditions
  @condition_traces.select(&:passed?)
end

#to_hObject



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