Class: Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Front
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Front
- Defined in:
- lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#front_type ⇒ Object
readonly
Returns the value of attribute front_type.
-
#humidity ⇒ Object
Returns the value of attribute humidity.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pressure ⇒ Object
Returns the value of attribute pressure.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
Instance Method Summary collapse
-
#advance!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Advance: pressure rises, front strengthens.
- #high_pressure? ⇒ Boolean
-
#initialize(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) ⇒ Front
constructor
A new instance of Front.
- #low_pressure? ⇒ Boolean
-
#retreat!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Retreat: pressure falls, front weakens.
- #severity_label ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) ⇒ Front
Returns a new instance of Front.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 15 def initialize(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) raise ArgumentError, "unknown front_type: #{front_type}" unless Constants::FRONT_TYPES.include?(front_type.to_sym) @id = SecureRandom.uuid @front_type = front_type.to_sym @domain = domain.to_s @pressure = pressure.clamp(0.0, 1.0) @temperature = temperature.clamp(0.0, 1.0) @humidity = humidity.clamp(0.0, 1.0) @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 12 def domain @domain end |
#front_type ⇒ Object (readonly)
Returns the value of attribute front_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 12 def front_type @front_type end |
#humidity ⇒ Object
Returns the value of attribute humidity.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 13 def humidity @humidity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 12 def id @id end |
#pressure ⇒ Object
Returns the value of attribute pressure.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 13 def pressure @pressure end |
#temperature ⇒ Object
Returns the value of attribute temperature.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 13 def temperature @temperature end |
Instance Method Details
#advance!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Advance: pressure rises, front strengthens
28 29 30 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 28 def advance!(rate = Constants::PRESSURE_CHANGE_RATE) @pressure = (@pressure + rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) end |
#high_pressure? ⇒ Boolean
37 38 39 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 37 def high_pressure? @pressure >= 0.65 end |
#low_pressure? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 41 def low_pressure? @pressure <= 0.35 end |
#retreat!(rate = Constants::PRESSURE_CHANGE_RATE) ⇒ Object
Retreat: pressure falls, front weakens
33 34 35 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 33 def retreat!(rate = Constants::PRESSURE_CHANGE_RATE) @pressure = (@pressure - rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) end |
#severity_label ⇒ Object
45 46 47 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 45 def severity_label Constants.label_for(Constants::SEVERITY_LABELS, @pressure) end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb', line 49 def to_h { id: @id, front_type: @front_type, domain: @domain, pressure: @pressure.round(10), temperature: @temperature.round(10), humidity: @humidity.round(10), high_pressure: high_pressure?, low_pressure: low_pressure?, severity: severity_label, created_at: @created_at.iso8601 } end |