Class: Legion::Extensions::Agentic::Executive::Compass::Helpers::Bearing

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(direction:, context:, confidence: nil) ⇒ Bearing

Returns a new instance of Bearing.



14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 14

def initialize(direction:, context:, confidence: nil)
  validate_direction!(direction)
  @id         = SecureRandom.uuid
  @direction  = direction.to_sym
  @value_axis = resolve_axis(direction.to_sym)
  @context    = context.to_s
  @confidence = (confidence || 0.7).to_f.clamp(0.0, 1.0).round(10)
  @taken_at   = Time.now.utc
end

Instance Attribute Details

#confidenceObject

Returns the value of attribute confidence.



12
13
14
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 12

def confidence
  @confidence
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 10

def context
  @context
end

#directionObject (readonly)

Returns the value of attribute direction.



10
11
12
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 10

def direction
  @direction
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 10

def id
  @id
end

#taken_atObject (readonly)

Returns the value of attribute taken_at.



10
11
12
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 10

def taken_at
  @taken_at
end

#value_axisObject (readonly)

Returns the value of attribute value_axis.



10
11
12
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 10

def value_axis
  @value_axis
end

Instance Method Details

#accuracy_labelObject



36
37
38
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 36

def accuracy_label
  Constants.label_for(Constants::ACCURACY_LABELS, @confidence)
end

#cardinal?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 32

def cardinal?
  Constants::CARDINAL_DIRECTIONS.key?(@direction)
end

#lost?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 28

def lost?
  @confidence < 0.2
end

#reliable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 24

def reliable?
  @confidence >= 0.6
end

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/executive/compass/helpers/bearing.rb', line 40

def to_h
  {
    id:             @id,
    direction:      @direction,
    value_axis:     @value_axis,
    context:        @context,
    confidence:     @confidence,
    accuracy_label: accuracy_label,
    cardinal:       cardinal?,
    reliable:       reliable?,
    lost:           lost?,
    taken_at:       @taken_at
  }
end