Class: Legion::Extensions::Agentic::Inference::Magnet::Helpers::Pole

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (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_atObject (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

#domainObject (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

#idObject (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_typeObject (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

#polarityObject (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

#strengthObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


48
49
50
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 48

def saturated?
  @strength >= 1.0
end

#strength_labelObject



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_hObject



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

Returns:

  • (Boolean)


52
53
54
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/pole.rb', line 52

def weak?
  @strength <= 0.1
end