Class: Legion::Extensions::Agentic::Defense::ImmuneResponse::Helpers::ImmuneResponse

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb

Constant Summary

Constants included from Constants

Constants::ANTIGEN_TYPES, Constants::DEFAULT_THREAT_LEVEL, Constants::HEALTH_LABELS, Constants::IMMUNITY_BOOST, Constants::IMMUNITY_DECAY, Constants::IMMUNITY_LABELS, Constants::MAX_ANTIBODIES, Constants::MAX_ANTIGENS, Constants::MAX_EXPOSURES, Constants::MAX_RESPONSES, Constants::MEMORY_CELL_THRESHOLD, Constants::REJECTION_THRESHOLD, Constants::RESPONSE_LABELS, Constants::RESPONSE_LEVELS, Constants::THREAT_ESCALATION, Constants::THREAT_LABELS, Constants::TOLERANCE_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Constants

label_for

Constructor Details

#initialize(antigen_id:, response_level:, antibody_id: nil, intensity: 0.5) ⇒ ImmuneResponse

Returns a new instance of ImmuneResponse.



17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 17

def initialize(antigen_id:, response_level:, antibody_id: nil, intensity: 0.5)
  @id             = SecureRandom.uuid
  @antigen_id     = antigen_id
  @antibody_id    = antibody_id
  @response_level = validate_response(response_level)
  @intensity      = intensity.to_f.clamp(0.0, 1.0).round(10)
  @action_taken   = nil
  @created_at     = Time.now.utc
end

Instance Attribute Details

#action_takenObject (readonly)

Returns the value of attribute action_taken.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def action_taken
  @action_taken
end

#antibody_idObject (readonly)

Returns the value of attribute antibody_id.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def antibody_id
  @antibody_id
end

#antigen_idObject (readonly)

Returns the value of attribute antigen_id.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def antigen_id
  @antigen_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def id
  @id
end

#intensityObject (readonly)

Returns the value of attribute intensity.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def intensity
  @intensity
end

#response_levelObject (readonly)

Returns the value of attribute response_level.



14
15
16
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 14

def response_level
  @response_level
end

Instance Method Details

#adaptive?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 32

def adaptive?
  !@antibody_id.nil?
end

#innate?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 36

def innate?
  @antibody_id.nil?
end

#record_action!(action) ⇒ Object



27
28
29
30
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 27

def record_action!(action)
  @action_taken = action.to_s
  self
end

#response_labelObject



44
45
46
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 44

def response_label
  Constants.label_for(RESPONSE_LABELS, @intensity)
end

#severe?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 40

def severe?
  @intensity >= REJECTION_THRESHOLD
end

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/legion/extensions/agentic/defense/immune_response/helpers/immune_response.rb', line 48

def to_h
  {
    id:             @id,
    antigen_id:     @antigen_id,
    antibody_id:    @antibody_id,
    response_level: @response_level,
    intensity:      @intensity,
    response_label: response_label,
    adaptive:       adaptive?,
    innate:         innate?,
    severe:         severe?,
    action_taken:   @action_taken,
    created_at:     @created_at
  }
end