Class: Legion::Extensions::Agentic::Inference::Magnet::Helpers::Pole
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Magnet::Helpers::Pole
- Defined in:
- lib/legion/extensions/agentic/inference/magnet/helpers/pole.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.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#material_type ⇒ Object
readonly
Returns the value of attribute material_type.
-
#polarity ⇒ Object
readonly
Returns the value of attribute polarity.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
Instance Method Summary collapse
- #attracts?(other_pole) ⇒ Boolean
- #demagnetize!(rate = Constants::DECAY_RATE) ⇒ Object
-
#initialize(polarity:, content:, strength: 0.5, material_type: :iron, domain: :general) ⇒ Pole
constructor
A new instance of Pole.
- #magnetize!(rate = Constants::ATTRACTION_RATE) ⇒ Object
- #repels?(other_pole) ⇒ Boolean
- #saturated? ⇒ Boolean
- #strength_label ⇒ Object
- #to_h ⇒ Object
- #weak? ⇒ Boolean
Constructor Details
#initialize(polarity:, content:, strength: 0.5, material_type: :iron, domain: :general) ⇒ Pole
Returns a new instance of Pole.
14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 14 def initialize(polarity:, content:, strength: 0.5, material_type: :iron, domain: :general) @id = SecureRandom.uuid @polarity = polarity @content = content @strength = strength.to_f.clamp(0.0, 1.0).round(10) @material_type = material_type @domain = domain @created_at = Time.now.utc end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.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/magnet/helpers/pole.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.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/magnet/helpers/pole.rb', line 12 def id @id end |
#material_type ⇒ Object (readonly)
Returns the value of attribute material_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 12 def material_type @material_type end |
#polarity ⇒ Object (readonly)
Returns the value of attribute polarity.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 12 def polarity @polarity end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 12 def strength @strength end |
Instance Method Details
#attracts?(other_pole) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 34 def attracts?(other_pole) return false if @polarity == :neutral || other_pole.polarity == :neutral return true if @polarity == :bipolar || other_pole.polarity == :bipolar @polarity != other_pole.polarity end |
#demagnetize!(rate = Constants::DECAY_RATE) ⇒ Object
29 30 31 32 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 29 def demagnetize!(rate = Constants::DECAY_RATE) @strength = (@strength - rate.to_f).clamp(0.0, 1.0).round(10) self end |
#magnetize!(rate = Constants::ATTRACTION_RATE) ⇒ Object
24 25 26 27 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 24 def magnetize!(rate = Constants::ATTRACTION_RATE) @strength = (@strength + rate.to_f).clamp(0.0, 1.0).round(10) self end |
#repels?(other_pole) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 41 def repels?(other_pole) return false if @polarity == :neutral || other_pole.polarity == :neutral return false if @polarity == :bipolar || other_pole.polarity == :bipolar @polarity == other_pole.polarity end |
#saturated? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 48 def saturated? @strength >= 1.0 end |
#strength_label ⇒ Object
56 57 58 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 56 def strength_label Constants.label_for(Constants::STRENGTH_LABELS, @strength) end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 60 def to_h { id: @id, polarity: @polarity, strength: @strength, material_type: @material_type, domain: @domain, content: @content, saturated: saturated?, weak: weak?, strength_label: strength_label, created_at: @created_at } end |
#weak? ⇒ Boolean
52 53 54 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 52 def weak? @strength <= 0.1 end |