Class: Legion::Extensions::Agentic::Social::Symbiosis::Helpers::SymbioticBond
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Social::Symbiosis::Helpers::SymbioticBond
- Defined in:
- lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb
Instance Attribute Summary collapse
-
#activation_count ⇒ Object
readonly
Returns the value of attribute activation_count.
-
#benefit_ratio ⇒ Object
readonly
Returns the value of attribute benefit_ratio.
-
#bond_id ⇒ Object
readonly
Returns the value of attribute bond_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#last_activated_at ⇒ Object
readonly
Returns the value of attribute last_activated_at.
-
#relationship_type ⇒ Object
readonly
Returns the value of attribute relationship_type.
-
#subsystem_a ⇒ Object
readonly
Returns the value of attribute subsystem_a.
-
#subsystem_b ⇒ Object
readonly
Returns the value of attribute subsystem_b.
Instance Method Summary collapse
- #activate!(amount: 0.05) ⇒ Object
- #decay!(rate: Constants::BOND_DECAY) ⇒ Object
- #dormant? ⇒ Boolean
-
#initialize(subsystem_a:, subsystem_b:, relationship_type:, strength: nil, benefit_ratio: nil) ⇒ SymbioticBond
constructor
A new instance of SymbioticBond.
- #involves?(subsystem_id) ⇒ Boolean
- #partner_of(subsystem_id) ⇒ Object
- #strength ⇒ Object
- #strength_label ⇒ Object
- #strong? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(subsystem_a:, subsystem_b:, relationship_type:, strength: nil, benefit_ratio: nil) ⇒ SymbioticBond
Returns a new instance of SymbioticBond.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 16 def initialize(subsystem_a:, subsystem_b:, relationship_type:, strength: nil, benefit_ratio: nil) validate_relationship_type!(relationship_type) @bond_id = SecureRandom.uuid @subsystem_a = subsystem_a @subsystem_b = subsystem_b @relationship_type = relationship_type @strength = (strength || Constants::DEFAULT_STRENGTH).clamp( Constants::MIN_STRENGTH, Constants::MAX_STRENGTH ) @benefit_ratio = benefit_ratio || default_benefit_ratio(relationship_type) @activation_count = 0 @created_at = Time.now.utc @last_activated_at = nil end |
Instance Attribute Details
#activation_count ⇒ Object (readonly)
Returns the value of attribute activation_count.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def activation_count @activation_count end |
#benefit_ratio ⇒ Object (readonly)
Returns the value of attribute benefit_ratio.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def benefit_ratio @benefit_ratio end |
#bond_id ⇒ Object (readonly)
Returns the value of attribute bond_id.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def bond_id @bond_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def created_at @created_at end |
#last_activated_at ⇒ Object (readonly)
Returns the value of attribute last_activated_at.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def last_activated_at @last_activated_at end |
#relationship_type ⇒ Object (readonly)
Returns the value of attribute relationship_type.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def relationship_type @relationship_type end |
#subsystem_a ⇒ Object (readonly)
Returns the value of attribute subsystem_a.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def subsystem_a @subsystem_a end |
#subsystem_b ⇒ Object (readonly)
Returns the value of attribute subsystem_b.
13 14 15 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 13 def subsystem_b @subsystem_b end |
Instance Method Details
#activate!(amount: 0.05) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 36 def activate!(amount: 0.05) delta = amount.clamp(0.0, 1.0) @strength = (@strength + delta).clamp(Constants::MIN_STRENGTH, Constants::MAX_STRENGTH) @activation_count += 1 @last_activated_at = Time.now.utc self end |
#decay!(rate: Constants::BOND_DECAY) ⇒ Object
44 45 46 47 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 44 def decay!(rate: Constants::BOND_DECAY) @strength = (@strength - rate).clamp(Constants::MIN_STRENGTH, Constants::MAX_STRENGTH) self end |
#dormant? ⇒ Boolean
49 50 51 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 49 def dormant? @strength <= Constants::DORMANT_THRESHOLD end |
#involves?(subsystem_id) ⇒ Boolean
64 65 66 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 64 def involves?(subsystem_id) [@subsystem_a, @subsystem_b].include?(subsystem_id) end |
#partner_of(subsystem_id) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 68 def partner_of(subsystem_id) return @subsystem_b if @subsystem_a == subsystem_id return @subsystem_a if @subsystem_b == subsystem_id nil end |
#strength ⇒ Object
32 33 34 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 32 def strength @strength.round(10) end |
#strength_label ⇒ Object
57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 57 def strength_label Constants::INTERACTION_STRENGTHS.each do |range, label| return label if range.cover?(@strength) end :dormant end |
#strong? ⇒ Boolean
53 54 55 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 53 def strong? @strength >= Constants::STRONG_THRESHOLD end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb', line 75 def to_h { bond_id: @bond_id, subsystem_a: @subsystem_a, subsystem_b: @subsystem_b, relationship_type: @relationship_type, strength: strength, strength_label: strength_label, benefit_ratio: @benefit_ratio, activation_count: @activation_count, dormant: dormant?, strong: strong?, created_at: @created_at.iso8601, last_activated_at: @last_activated_at&.iso8601 } end |