Class: Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Snowpack
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Avalanche::Helpers::Snowpack
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb
Constant Summary
Constants included
from Constants
Constants::ACCUMULATION_RATE, Constants::CASCADE_TYPES, Constants::MAGNITUDE_LABELS, Constants::MAX_CASCADE_HISTORY, Constants::MAX_SNOWPACKS, Constants::MELT_RATE, Constants::SNOWPACK_TYPES, Constants::STABILITY_LABELS, Constants::TRIGGER_THRESHOLD
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Constants
label_for
Constructor Details
#initialize(snowpack_type:, domain:, content:, depth: 0.0, stability: 1.0) ⇒ Snowpack
Returns a new instance of Snowpack.
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 17
def initialize(snowpack_type:, domain:, content:, depth: 0.0, stability: 1.0, **)
raise ArgumentError, "unknown snowpack_type: #{snowpack_type}" unless Constants::SNOWPACK_TYPES.include?(snowpack_type)
@id = SecureRandom.uuid
@snowpack_type = snowpack_type
@domain = domain
@content = content
@depth = depth.clamp(0.0, 1.0)
@stability = stability.clamp(0.0, 1.0)
@created_at = Time.now.utc
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
14
15
16
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 14
def content
@content
end
|
#created_at ⇒ Object
Returns the value of attribute created_at.
14
15
16
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 14
def created_at
@created_at
end
|
#depth ⇒ Object
Returns the value of attribute depth.
15
16
17
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 15
def depth
@depth
end
|
#domain ⇒ Object
Returns the value of attribute domain.
14
15
16
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 14
def domain
@domain
end
|
#id ⇒ Object
Returns the value of attribute id.
14
15
16
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 14
def id
@id
end
|
#snowpack_type ⇒ Object
Returns the value of attribute snowpack_type.
14
15
16
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 14
def snowpack_type
@snowpack_type
end
|
#stability ⇒ Object
Returns the value of attribute stability.
15
16
17
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 15
def stability
@stability
end
|
Instance Method Details
#accumulate!(rate = Constants::ACCUMULATION_RATE) ⇒ Object
29
30
31
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 29
def accumulate!(rate = Constants::ACCUMULATION_RATE)
@depth = (@depth + rate.abs).clamp(0.0, 1.0).round(10)
end
|
#compact! ⇒ Object
33
34
35
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 33
def compact!
@stability = (@stability + 0.05).clamp(0.0, 1.0).round(10)
end
|
#critical? ⇒ Boolean
53
54
55
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 53
def critical?
@stability < 0.2
end
|
#destabilize!(force) ⇒ Object
41
42
43
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 41
def destabilize!(force)
@stability = (@stability - force.abs).clamp(0.0, 1.0).round(10)
end
|
#instability ⇒ Object
61
62
63
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 61
def instability
(1.0 - @stability).round(10)
end
|
#melt!(rate = Constants::MELT_RATE) ⇒ Object
37
38
39
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 37
def melt!(rate = Constants::MELT_RATE)
@depth = (@depth - rate.abs).clamp(0.0, 1.0).round(10)
end
|
#stability_label ⇒ Object
57
58
59
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 57
def stability_label
Constants.label_for(:STABILITY_LABELS, @stability)
end
|
#stable? ⇒ Boolean
45
46
47
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 45
def stable?
@stability >= 0.6
end
|
#to_h ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 65
def to_h
{
id: @id,
snowpack_type: @snowpack_type,
domain: @domain,
content: @content,
depth: @depth,
stability: @stability,
stable: stable?,
unstable: unstable?,
critical: critical?,
stability_label: stability_label,
created_at: @created_at
}
end
|
#unstable? ⇒ Boolean
49
50
51
|
# File 'lib/legion/extensions/agentic/defense/avalanche/helpers/snowpack.rb', line 49
def unstable?
@stability < 0.4
end
|