Class: Legion::Extensions::Agentic::Defense::Erosion::Helpers::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/defense/erosion/helpers/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formation_id:, agent:, depth: 0.0, width: 0.1, flow_rate: 0.0) ⇒ Channel

Returns a new instance of Channel.

Raises:

  • (ArgumentError)


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

#agentObject (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_idObject (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_atObject (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

#depthObject (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_rateObject (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_idObject (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_atObject (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_atObject (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

#widthObject (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

Returns:

  • (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_labelObject



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

Returns:

  • (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_hObject



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