Class: Legion::Extensions::Agentic::Defense::Immunology::Helpers::Antibody

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tactic:, pattern:, strength: 0.5) ⇒ Antibody

Returns a new instance of Antibody.



15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 15

def initialize(tactic:, pattern:, strength: 0.5)
  @id       = SecureRandom.uuid
  @tactic   = tactic
  @pattern  = pattern
  @strength = strength.clamp(0.0, 1.0)
  @matches  = 0
  @created_at = Time.now.utc
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 12

def id
  @id
end

#matchesObject

Returns the value of attribute matches.



13
14
15
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 13

def matches
  @matches
end

#patternObject (readonly)

Returns the value of attribute pattern.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 12

def pattern
  @pattern
end

#strengthObject

Returns the value of attribute strength.



13
14
15
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 13

def strength
  @strength
end

#tacticObject (readonly)

Returns the value of attribute tactic.



12
13
14
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 12

def tactic
  @tactic
end

Instance Method Details

#decay!Object



30
31
32
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 30

def decay!
  @strength = (@strength - Constants::RESISTANCE_DECAY).clamp(0.0, 1.0).round(10)
end

#effective?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 34

def effective?
  @strength >= 0.3
end

#match!Object



24
25
26
27
28
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 24

def match!
  @matches += 1
  boost = Constants::RESISTANCE_BOOST / (@matches + 1)
  @strength = (@strength + boost.round(10)).clamp(0.0, 1.0).round(10)
end

#to_hObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb', line 38

def to_h
  {
    id:         @id,
    tactic:     @tactic,
    pattern:    @pattern,
    strength:   @strength,
    matches:    @matches,
    effective:  effective?,
    created_at: @created_at
  }
end