Class: Legion::Extensions::Agentic::Self::Anchor::Helpers::Anchor
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Anchor::Helpers::Anchor
- Defined in:
- lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb
Instance Attribute Summary collapse
-
#anchor_type ⇒ Object
readonly
Returns the value of attribute anchor_type.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#grip ⇒ Object
Returns the value of attribute grip.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#reference_value ⇒ Object
readonly
Returns the value of attribute reference_value.
-
#weight ⇒ Object
Returns the value of attribute weight.
Instance Method Summary collapse
- #bias_pull(new_value) ⇒ Object
- #drag!(rate: Constants::DRAG_RATE) ⇒ Object
- #drift!(rate: Constants::DRIFT_RATE) ⇒ Object
- #drifting? ⇒ Boolean
- #grip_label ⇒ Object
- #heavy? ⇒ Boolean
-
#initialize(anchor_type:, domain:, content:, reference_value: nil, grip: nil, weight: nil) ⇒ Anchor
constructor
A new instance of Anchor.
- #ironclad? ⇒ Boolean
- #light? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(anchor_type:, domain:, content:, reference_value: nil, grip: nil, weight: nil) ⇒ Anchor
Returns a new instance of Anchor.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 14 def initialize(anchor_type:, domain:, content:, reference_value: nil, grip: nil, weight: nil) validate_anchor_type!(anchor_type) @id = SecureRandom.uuid @anchor_type = anchor_type.to_sym @domain = domain.to_sym @content = content.to_s @reference_value = (reference_value || 0.5).to_f.clamp(0.0, 1.0).round(10) @grip = (grip || 0.7).to_f.clamp(0.0, 1.0).round(10) @weight = (weight || 0.5).to_f.clamp(0.0, 1.0).round(10) @created_at = Time.now.utc end |
Instance Attribute Details
#anchor_type ⇒ Object (readonly)
Returns the value of attribute anchor_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def anchor_type @anchor_type end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def domain @domain end |
#grip ⇒ Object
Returns the value of attribute grip.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 12 def grip @grip end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def id @id end |
#reference_value ⇒ Object (readonly)
Returns the value of attribute reference_value.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 10 def reference_value @reference_value end |
#weight ⇒ Object
Returns the value of attribute weight.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 12 def weight @weight end |
Instance Method Details
#bias_pull(new_value) ⇒ Object
35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 35 def bias_pull(new_value) pull_strength = @grip * @weight adjusted = new_value + ((reference_value - new_value) * pull_strength) adjusted.clamp(0.0, 1.0).round(10) end |
#drag!(rate: Constants::DRAG_RATE) ⇒ Object
27 28 29 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 27 def drag!(rate: Constants::DRAG_RATE) @grip = (@grip + rate.abs).clamp(0.0, 1.0).round(10) end |
#drift!(rate: Constants::DRIFT_RATE) ⇒ Object
31 32 33 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 31 def drift!(rate: Constants::DRIFT_RATE) @grip = (@grip - rate.abs).clamp(0.0, 1.0).round(10) end |
#drifting? ⇒ Boolean
45 46 47 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 45 def drifting? @grip < 0.2 end |
#grip_label ⇒ Object
57 58 59 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 57 def grip_label Constants.label_for(Constants::GRIP_LABELS, @grip) end |
#heavy? ⇒ Boolean
49 50 51 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 49 def heavy? @weight >= 0.7 end |
#ironclad? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 41 def ironclad? @grip >= 0.8 end |
#light? ⇒ Boolean
53 54 55 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 53 def light? @weight < 0.3 end |
#to_h ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/anchor.rb', line 61 def to_h { id: @id, anchor_type: @anchor_type, domain: @domain, content: @content, reference_value: @reference_value, grip: @grip, weight: @weight, grip_label: grip_label, ironclad: ironclad?, drifting: drifting?, created_at: @created_at } end |