Class: Legion::Extensions::Agentic::Defense::Erosion::Helpers::Channel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Erosion::Helpers::Channel
- Defined in:
- lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#channel_id ⇒ Object
readonly
Returns the value of attribute channel_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#flow_rate ⇒ Object
readonly
Returns the value of attribute flow_rate.
-
#formation_id ⇒ Object
readonly
Returns the value of attribute formation_id.
-
#last_active_at ⇒ Object
readonly
Returns the value of attribute last_active_at.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #deepen!(force) ⇒ Object
- #depth_label ⇒ Object
- #dormant? ⇒ Boolean
-
#initialize(formation_id:, agent:, depth: 0.0, width: 0.1, flow_rate: 0.0) ⇒ Channel
constructor
A new instance of Channel.
- #to_h ⇒ Object
- #widen!(amount = 0.05) ⇒ Object
Constructor Details
#initialize(formation_id:, agent:, depth: 0.0, width: 0.1, flow_rate: 0.0) ⇒ Channel
Returns a new instance of Channel.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 15 def initialize(formation_id:, agent:, depth: 0.0, width: 0.1, flow_rate: 0.0, **) raise ArgumentError, "invalid agent: #{agent}" unless Constants::EROSION_AGENTS.include?(agent) @channel_id = SecureRandom.uuid @formation_id = formation_id @agent = agent @depth = depth.clamp(0.0, 1.0).round(10) @width = width.clamp(0.0, 1.0).round(10) @flow_rate = flow_rate.clamp(0.0, 1.0).round(10) @created_at = Time.now.utc @updated_at = Time.now.utc @last_active_at = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def agent @agent end |
#channel_id ⇒ Object (readonly)
Returns the value of attribute channel_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def channel_id @channel_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def created_at @created_at end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def depth @depth end |
#flow_rate ⇒ Object (readonly)
Returns the value of attribute flow_rate.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def flow_rate @flow_rate end |
#formation_id ⇒ Object (readonly)
Returns the value of attribute formation_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def formation_id @formation_id end |
#last_active_at ⇒ Object (readonly)
Returns the value of attribute last_active_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def last_active_at @last_active_at end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def updated_at @updated_at end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 12 def width @width end |
Instance Method Details
#active? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 51 def active? !dormant? end |
#deepen!(force) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 29 def deepen!(force) force = force.clamp(0.0, 1.0) @depth = (@depth + force).clamp(0.0, 1.0).round(10) @flow_rate = [@flow_rate + (force * 0.1), 1.0].min.round(10) @last_active_at = Time.now.utc @updated_at = Time.now.utc { depth: @depth, flow_rate: @flow_rate } end |
#depth_label ⇒ Object
55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 55 def depth_label Constants::CHANNEL_DEPTH_LABELS.each do |range, label| return label if range.cover?(@depth) end :surface_scratch end |
#dormant? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 45 def dormant? return true if @last_active_at.nil? (Time.now.utc - @last_active_at) > 3600 end |
#to_h ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 62 def to_h { channel_id: @channel_id, formation_id: @formation_id, agent: @agent, depth: @depth, width: @width, flow_rate: @flow_rate, depth_label: depth_label, dormant: dormant?, active: active?, created_at: @created_at, updated_at: @updated_at, last_active_at: @last_active_at } end |
#widen!(amount = 0.05) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb', line 38 def widen!(amount = 0.05) amount = amount.clamp(0.0, 1.0) @width = (@width + amount).clamp(0.0, 1.0).round(10) @updated_at = Time.now.utc { width: @width } end |