Class: DecisionAgent::Evaluation

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

Overview

Single evaluation produced by an evaluator: a suggested decision, weight, reason, and optional metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decision:, weight:, reason:, evaluator_name:, metadata: {}) ⇒ Evaluation

Returns a new instance of Evaluation.

Parameters:

  • decision (String, #to_s)

    The suggested decision value

  • weight (Numeric)

    Importance of this evaluation (0.0 to 1.0)

  • reason (String, #to_s)

    Human-readable reason for the decision

  • evaluator_name (String, #to_s)

    Name of the evaluator that produced this

  • metadata (Hash) (defaults to: {})

    Optional extra data (e.g. explainability)

Raises:



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/decision_agent/evaluation.rb', line 14

def initialize(decision:, weight:, reason:, evaluator_name:, metadata: {})
  validate_weight!(weight)

  @decision = decision.to_s.freeze
  @weight = weight.to_f
  @reason = reason.to_s.freeze
  @evaluator_name = evaluator_name.to_s.freeze
  @metadata = deep_freeze()

  freeze
end

Instance Attribute Details

#decisionObject (readonly)

Returns the value of attribute decision.



6
7
8
# File 'lib/decision_agent/evaluation.rb', line 6

def decision
  @decision
end

#evaluator_nameObject (readonly)

Returns the value of attribute evaluator_name.



6
7
8
# File 'lib/decision_agent/evaluation.rb', line 6

def evaluator_name
  @evaluator_name
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/decision_agent/evaluation.rb', line 6

def 
  @metadata
end

#reasonObject (readonly)

Returns the value of attribute reason.



6
7
8
# File 'lib/decision_agent/evaluation.rb', line 6

def reason
  @reason
end

#weightObject (readonly)

Returns the value of attribute weight.



6
7
8
# File 'lib/decision_agent/evaluation.rb', line 6

def weight
  @weight
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if other is an Evaluation with same attributes.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Boolean)

    true if other is an Evaluation with same attributes



39
40
41
42
43
44
45
46
# File 'lib/decision_agent/evaluation.rb', line 39

def ==(other)
  other.is_a?(Evaluation) &&
    @decision == other.decision &&
    @weight == other.weight &&
    @reason == other.reason &&
    @evaluator_name == other.evaluator_name &&
    @metadata == other.
end

#to_hHash

Returns Symbol-keyed hash of decision, weight, reason, evaluator_name, metadata.

Returns:

  • (Hash)

    Symbol-keyed hash of decision, weight, reason, evaluator_name, metadata



27
28
29
30
31
32
33
34
35
# File 'lib/decision_agent/evaluation.rb', line 27

def to_h
  {
    decision: @decision,
    weight: @weight,
    reason: @reason,
    evaluator_name: @evaluator_name,
    metadata: @metadata
  }
end