Class: Legion::Extensions::Agentic::Inference::Gravity::Helpers::Attractor
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Gravity::Helpers::Attractor
- Defined in:
- lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#decay_rate ⇒ Object
readonly
Returns the value of attribute decay_rate.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#mass ⇒ Object
readonly
Returns the value of attribute mass.
-
#pull_radius ⇒ Object
readonly
Returns the value of attribute pull_radius.
-
#reinforcement_count ⇒ Object
readonly
Returns the value of attribute reinforcement_count.
Instance Method Summary collapse
- #accrete!(amount = Constants::MASS_ACCRETION) ⇒ Object
- #collapsed? ⇒ Boolean
- #erode!(amount = Constants::MASS_EROSION) ⇒ Object
-
#initialize(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) ⇒ Attractor
constructor
A new instance of Attractor.
- #mass_label ⇒ Object
- #pull_strength_at(distance:) ⇒ Object
- #supermassive? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) ⇒ Attractor
Returns a new instance of Attractor.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 14 def initialize(content:, domain: :unknown, mass: Constants::DEFAULT_MASS, pull_radius: 1.0, decay_rate: 0.01) @id = SecureRandom.uuid @content = content @domain = domain @mass = mass.to_f.round(10) @pull_radius = pull_radius.clamp(0.01, Float::INFINITY) @decay_rate = decay_rate.clamp(0.0, 1.0) @created_at = Time.now.utc @reinforcement_count = 0 end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def created_at @created_at end |
#decay_rate ⇒ Object (readonly)
Returns the value of attribute decay_rate.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def decay_rate @decay_rate end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def id @id end |
#mass ⇒ Object (readonly)
Returns the value of attribute mass.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def mass @mass end |
#pull_radius ⇒ Object (readonly)
Returns the value of attribute pull_radius.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def pull_radius @pull_radius end |
#reinforcement_count ⇒ Object (readonly)
Returns the value of attribute reinforcement_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 12 def reinforcement_count @reinforcement_count end |
Instance Method Details
#accrete!(amount = Constants::MASS_ACCRETION) ⇒ Object
26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 26 def accrete!(amount = Constants::MASS_ACCRETION) @mass = (@mass + amount.to_f).round(10) @reinforcement_count += 1 self end |
#collapsed? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 44 def collapsed? @mass < Constants::COLLAPSE_THRESHOLD end |
#erode!(amount = Constants::MASS_EROSION) ⇒ Object
32 33 34 35 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 32 def erode!(amount = Constants::MASS_EROSION) @mass = [(@mass - amount.to_f).round(10), 0.0].max self end |
#mass_label ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 52 def mass_label Constants.label_for(Constants::MASS_LABELS, @mass) end |
#pull_strength_at(distance:) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 37 def pull_strength_at(distance:) return 0.0 if distance <= 0 || distance > @pull_radius raw = (Constants::PULL_CONSTANT * @mass) / (distance**2) raw.clamp(0.0, @mass) end |
#supermassive? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 48 def supermassive? @mass >= Constants::SUPERMASSIVE_THRESHOLD end |
#to_h ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/legion/extensions/agentic/inference/gravity/helpers/attractor.rb', line 56 def to_h { id: @id, content: @content, domain: @domain, mass: @mass, pull_radius: @pull_radius, decay_rate: @decay_rate, reinforcement_count: @reinforcement_count, collapsed: collapsed?, supermassive: supermassive?, mass_label: mass_label, created_at: @created_at } end |