Class: Legion::Extensions::Agentic::Learning::Chrysalis::Helpers::Cocoon
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Chrysalis::Helpers::Cocoon
- Defined in:
- lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb
Constant Summary collapse
- TEMP_ADJUST =
0.05- HUMID_ADJUST =
0.05
Instance Attribute Summary collapse
-
#chrysalis_ids ⇒ Object
readonly
Returns the value of attribute chrysalis_ids.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#humidity ⇒ Object
readonly
Returns the value of attribute humidity.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#temperature ⇒ Object
readonly
Returns the value of attribute temperature.
Instance Method Summary collapse
- #cool! ⇒ Object
- #dry! ⇒ Object
- #expose(chrysalis_id) ⇒ Object
- #growth_modifier ⇒ Object
- #hostile? ⇒ Boolean
- #ideal? ⇒ Boolean
-
#initialize(environment:, temperature: 0.5, humidity: 0.5) ⇒ Cocoon
constructor
A new instance of Cocoon.
- #moisten! ⇒ Object
- #shelter(chrysalis_id) ⇒ Object
- #to_h ⇒ Object
- #warm! ⇒ Object
Constructor Details
#initialize(environment:, temperature: 0.5, humidity: 0.5) ⇒ Cocoon
Returns a new instance of Cocoon.
17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 17 def initialize(environment:, temperature: 0.5, humidity: 0.5, **) @id = SecureRandom.uuid @environment = environment.to_s @temperature = temperature.to_f.clamp(0.0, 1.0) @humidity = humidity.to_f.clamp(0.0, 1.0) @chrysalis_ids = [] @created_at = Time.now.utc end |
Instance Attribute Details
#chrysalis_ids ⇒ Object (readonly)
Returns the value of attribute chrysalis_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def chrysalis_ids @chrysalis_ids end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def created_at @created_at end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def environment @environment end |
#humidity ⇒ Object (readonly)
Returns the value of attribute humidity.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def humidity @humidity end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def id @id end |
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 12 def temperature @temperature end |
Instance Method Details
#cool! ⇒ Object
40 41 42 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 40 def cool! @temperature = (@temperature - TEMP_ADJUST).clamp(0.0, 1.0).round(10) end |
#dry! ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 48 def dry! @humidity = (@humidity - HUMID_ADJUST).clamp(0.0, 1.0).round(10) end |
#expose(chrysalis_id) ⇒ Object
31 32 33 34 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 31 def expose(chrysalis_id) @chrysalis_ids.delete(chrysalis_id) true end |
#growth_modifier ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 60 def growth_modifier if ideal? 0.1 elsif hostile? -0.05 else 0.0 end end |
#hostile? ⇒ Boolean
56 57 58 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 56 def hostile? @temperature > 0.9 || @humidity < 0.1 end |
#ideal? ⇒ Boolean
52 53 54 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 52 def ideal? @temperature.between?(0.4, 0.7) && @humidity.between?(0.4, 0.7) end |
#moisten! ⇒ Object
44 45 46 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 44 def moisten! @humidity = (@humidity + HUMID_ADJUST).clamp(0.0, 1.0).round(10) end |
#shelter(chrysalis_id) ⇒ Object
26 27 28 29 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 26 def shelter(chrysalis_id) @chrysalis_ids << chrysalis_id unless @chrysalis_ids.include?(chrysalis_id) true end |
#to_h ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 70 def to_h { id: @id, environment: @environment, temperature: @temperature, humidity: @humidity, chrysalis_ids: @chrysalis_ids.dup, ideal: ideal?, hostile: hostile?, growth_modifier: growth_modifier, created_at: @created_at } end |
#warm! ⇒ Object
36 37 38 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/cocoon.rb', line 36 def warm! @temperature = (@temperature + TEMP_ADJUST).clamp(0.0, 1.0).round(10) end |