Class: Legion::Extensions::Agentic::Homeostasis::Weather::Helpers::Front

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/weather/helpers/front.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(front_type:, domain:, pressure: 0.5, temperature: 0.5, humidity: 0.5) ⇒ Front

Returns a new instance of Front.

Raises:

  • (ArgumentError)


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_atObject (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

#domainObject (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_typeObject (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

#humidityObject

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

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

#pressureObject

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

#temperatureObject

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

Returns:

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

Returns:

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



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_hObject



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