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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bias_type:, domain:, declination: nil, strength: nil) ⇒ MagneticBias

Returns a new instance of MagneticBias.



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

def initialize(bias_type:, domain:, declination: nil, strength: nil)
  validate_bias!(bias_type)
  @id           = SecureRandom.uuid
  @bias_type    = bias_type.to_sym
  @domain       = domain.to_sym
  @declination  = (declination || 0.3).to_f.clamp(0.0, 1.0).round(10)
  @strength     = (strength || 0.5).to_f.clamp(0.0, 1.0).round(10)
  @detected_at  = Time.now.utc
end

Instance Attribute Details

#bias_typeObject (readonly)

Returns the value of attribute bias_type.



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

def bias_type
  @bias_type
end

#declinationObject

Returns the value of attribute declination.



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

def declination
  @declination
end

#detected_atObject (readonly)

Returns the value of attribute detected_at.



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

def detected_at
  @detected_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#strengthObject

Returns the value of attribute strength.



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

def strength
  @strength
end

Instance Method Details

#correct!(amount: Constants::CALIBRATION_BOOST) ⇒ Object



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

def correct!(amount: Constants::CALIBRATION_BOOST)
  @declination = (@declination - amount.abs).clamp(0.0, 1.0).round(10)
  self
end

#decay!(rate: Constants::DECLINATION_DECAY) ⇒ Object



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

def decay!(rate: Constants::DECLINATION_DECAY)
  @strength = (@strength - rate.abs).clamp(0.0, 1.0).round(10)
  @declination = (@declination - (rate.abs * 0.5)).clamp(0.0, 1.0).round(10)
  self
end

#declination_labelObject



48
49
50
# File 'lib/legion/extensions/agentic/executive/compass/helpers/magnetic_bias.rb', line 48

def declination_label
  Constants.label_for(Constants::DECLINATION_LABELS, @declination)
end

#intensify!(amount: 0.1) ⇒ Object



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

def intensify!(amount: 0.1)
  @strength = (@strength + amount.abs).clamp(0.0, 1.0).round(10)
  @declination = (@declination + (amount.abs * 0.5)).clamp(0.0, 1.0).round(10)
  self
end

#negligible?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/legion/extensions/agentic/executive/compass/helpers/magnetic_bias.rb', line 44

def negligible?
  @declination < 0.2
end

#severe?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/legion/extensions/agentic/executive/compass/helpers/magnetic_bias.rb', line 40

def severe?
  @declination >= 0.8
end

#to_hObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/legion/extensions/agentic/executive/compass/helpers/magnetic_bias.rb', line 52

def to_h
  {
    id:                @id,
    bias_type:         @bias_type,
    domain:            @domain,
    declination:       @declination,
    declination_label: declination_label,
    strength:          @strength,
    severe:            severe?,
    negligible:        negligible?,
    detected_at:       @detected_at
  }
end