Class: Legion::Extensions::Agentic::Defense::Immunology::Helpers::Antibody
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Immunology::Helpers::Antibody
- Defined in:
- lib/legion/extensions/agentic/defense/immunology/helpers/antibody.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#matches ⇒ Object
Returns the value of attribute matches.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#strength ⇒ Object
Returns the value of attribute strength.
-
#tactic ⇒ Object
readonly
Returns the value of attribute tactic.
Instance Method Summary collapse
- #decay! ⇒ Object
- #effective? ⇒ Boolean
-
#initialize(tactic:, pattern:, strength: 0.5) ⇒ Antibody
constructor
A new instance of Antibody.
- #match! ⇒ Object
- #to_h ⇒ Object
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_at ⇒ Object (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 |
#id ⇒ Object (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 |
#matches ⇒ Object
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 |
#pattern ⇒ Object (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 |
#strength ⇒ Object
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 |
#tactic ⇒ Object (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
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_h ⇒ Object
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 |