Class: Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Storm
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Storm
- Defined in:
- lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#front_ids ⇒ Object
readonly
Returns the value of attribute front_ids.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#insight_log ⇒ Object
readonly
Returns the value of attribute insight_log.
-
#intensity ⇒ Object
Returns the value of attribute intensity.
Instance Method Summary collapse
- #clarity_label ⇒ Object
- #clearing? ⇒ Boolean
-
#dissipate!(rate = Constants::DISSIPATION_RATE) ⇒ Object
Dissipate: storm weakens and clears.
-
#initialize(condition:, front_ids: [], intensity: 0.5, coverage: 0.5) ⇒ Storm
constructor
A new instance of Storm.
-
#intensify!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Intensify: storm grows stronger.
-
#lightning_strike!(domain: nil) ⇒ Object
A lightning strike of sudden insight — random intensity, logged for audit.
- #raging? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(condition:, front_ids: [], intensity: 0.5, coverage: 0.5) ⇒ Storm
Returns a new instance of Storm.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 15 def initialize(condition:, front_ids: [], intensity: 0.5, coverage: 0.5) raise ArgumentError, "unknown condition: #{condition}" unless Constants::CONDITION_TYPES.include?(condition.to_sym) @id = SecureRandom.uuid @condition = condition.to_sym @front_ids = Array(front_ids).dup @intensity = intensity.clamp(0.0, 1.0) @coverage = coverage.clamp(0.0, 1.0) @created_at = Time.now.utc @insight_log = [] end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12 def condition @condition end |
#coverage ⇒ Object
Returns the value of attribute coverage.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 13 def coverage @coverage end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12 def created_at @created_at end |
#front_ids ⇒ Object (readonly)
Returns the value of attribute front_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12 def front_ids @front_ids end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12 def id @id end |
#insight_log ⇒ Object (readonly)
Returns the value of attribute insight_log.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 12 def insight_log @insight_log end |
#intensity ⇒ Object
Returns the value of attribute intensity.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 13 def intensity @intensity end |
Instance Method Details
#clarity_label ⇒ Object
61 62 63 64 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 61 def clarity_label # Clarity is inverse of intensity: high intensity = low clarity Constants.label_for(Constants::CLARITY_LABELS, 1.0 - @intensity) end |
#clearing? ⇒ Boolean
57 58 59 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 57 def clearing? @intensity <= 0.25 end |
#dissipate!(rate = Constants::DISSIPATION_RATE) ⇒ Object
Dissipate: storm weakens and clears
34 35 36 37 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 34 def dissipate!(rate = Constants::DISSIPATION_RATE) @intensity = (@intensity - rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) @coverage = (@coverage - (rate * 0.5).clamp(0.0, 1.0)).clamp(0.0, 1.0) end |
#intensify!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Intensify: storm grows stronger
28 29 30 31 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 28 def intensify!(rate = Constants::PRESSURE_CHANGE_RATE) @intensity = (@intensity + rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) @coverage = (@coverage + (rate * 0.5).clamp(0.0, 1.0)).clamp(0.0, 1.0) end |
#lightning_strike!(domain: nil) ⇒ Object
A lightning strike of sudden insight — random intensity, logged for audit
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 40 def lightning_strike!(domain: nil) insight_id = SecureRandom.uuid insight_intensity = rand.round(10) entry = { id: insight_id, domain: domain, intensity: insight_intensity, struck_at: Time.now.utc.iso8601 } @insight_log << entry entry end |
#raging? ⇒ Boolean
53 54 55 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 53 def raging? @intensity >= 0.75 end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/storm.rb', line 66 def to_h { id: @id, condition: @condition, front_ids: @front_ids, intensity: @intensity.round(10), coverage: @coverage.round(10), raging: raging?, clearing: clearing?, clarity: clarity_label, insight_count: @insight_log.size, created_at: @created_at.iso8601 } end |