Class: Legion::Extensions::Agentic::Defense::Quicksand::Helpers::Trap
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Quicksand::Helpers::Trap
- Defined in:
- lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#struggle_count ⇒ Object
readonly
Returns the value of attribute struggle_count.
-
#trap_type ⇒ Object
readonly
Returns the value of attribute trap_type.
-
#viscosity ⇒ Object
Returns the value of attribute viscosity.
Instance Method Summary collapse
- #calm!(rate: Constants::CALM_RATE) ⇒ Object
- #depth_label ⇒ Object
- #escape! ⇒ Object
-
#initialize(trap_type:, domain:, content:, depth: nil, viscosity: nil) ⇒ Trap
constructor
A new instance of Trap.
- #sink!(rate: Constants::SINK_RATE) ⇒ Object
- #struggle! ⇒ Object
- #stuck? ⇒ Boolean
- #submerged? ⇒ Boolean
- #surface? ⇒ Boolean
- #to_h ⇒ Object
- #viscosity_label ⇒ Object
Constructor Details
#initialize(trap_type:, domain:, content:, depth: nil, viscosity: nil) ⇒ Trap
Returns a new instance of Trap.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 14 def initialize(trap_type:, domain:, content:, depth: nil, viscosity: nil) validate_trap_type!(trap_type) @id = SecureRandom.uuid @trap_type = trap_type.to_sym @domain = domain.to_sym @content = content.to_s @depth = (depth || 0.3).to_f.clamp(0.0, 1.0).round(10) @viscosity = (viscosity || 0.5).to_f.clamp(0.0, 1.0).round(10) @struggle_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def created_at @created_at end |
#depth ⇒ Object
Returns the value of attribute depth.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 12 def depth @depth end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def id @id end |
#struggle_count ⇒ Object (readonly)
Returns the value of attribute struggle_count.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def struggle_count @struggle_count end |
#trap_type ⇒ Object (readonly)
Returns the value of attribute trap_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 10 def trap_type @trap_type end |
#viscosity ⇒ Object
Returns the value of attribute viscosity.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 12 def viscosity @viscosity end |
Instance Method Details
#calm!(rate: Constants::CALM_RATE) ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 37 def calm!(rate: Constants::CALM_RATE) @depth = (@depth - rate.abs).clamp(0.0, 1.0).round(10) end |
#depth_label ⇒ Object
60 61 62 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 60 def depth_label Constants.label_for(Constants::DEPTH_LABELS, @depth) end |
#escape! ⇒ Object
41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 41 def escape! return :too_deep if @depth > (1.0 - Constants::ESCAPE_THRESHOLD) @depth = 0.0 :escaped end |
#sink!(rate: Constants::SINK_RATE) ⇒ Object
27 28 29 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 27 def sink!(rate: Constants::SINK_RATE) @depth = (@depth + rate.abs).clamp(0.0, 1.0).round(10) end |
#struggle! ⇒ Object
31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 31 def struggle! @struggle_count += 1 penalty = Constants::STRUGGLE_PENALTY * @viscosity @depth = (@depth + penalty).clamp(0.0, 1.0).round(10) end |
#stuck? ⇒ Boolean
56 57 58 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 56 def stuck? @depth >= 0.5 && @viscosity >= 0.5 end |
#submerged? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 48 def submerged? @depth >= 0.8 end |
#surface? ⇒ Boolean
52 53 54 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 52 def surface? @depth < 0.2 end |
#to_h ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 68 def to_h { id: @id, trap_type: @trap_type, domain: @domain, content: @content, depth: @depth, viscosity: @viscosity, depth_label: depth_label, viscosity_label: viscosity_label, struggle_count: @struggle_count, submerged: submerged?, surface: surface?, stuck: stuck?, created_at: @created_at } end |
#viscosity_label ⇒ Object
64 65 66 |
# File 'lib/legion/extensions/agentic/defense/quicksand/helpers/trap.rb', line 64 def viscosity_label Constants.label_for(Constants::VISCOSITY_LABELS, @viscosity) end |