Class: Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Cocoon
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Cocoon
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb
Constant Summary
Constants included from Constants
Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::COCOON_TYPES, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::GESTATION_STAGES, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::MATURITY_LABELS, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::MATURITY_RATE, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::MAX_COCOONS, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::PREMATURE_PENALTY, Legion::Extensions::Agentic::Homeostasis::Cocoon::Helpers::Constants::PROTECTION_BY_TYPE
Instance Attribute Summary collapse
-
#cocoon_type ⇒ Object
readonly
Returns the value of attribute cocoon_type.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#maturity ⇒ Object
readonly
Returns the value of attribute maturity.
-
#protection ⇒ Object
readonly
Returns the value of attribute protection.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Instance Method Summary collapse
- #age_seconds ⇒ Object
- #emerge! ⇒ Object
- #expose! ⇒ Object
- #gestate!(rate = MATURITY_RATE) ⇒ Object
-
#initialize(cocoon_type:, domain:, content: '', maturity: nil, protection: nil) ⇒ Cocoon
constructor
A new instance of Cocoon.
- #premature? ⇒ Boolean
- #ready? ⇒ Boolean
- #to_h ⇒ Object
Methods included from Constants
Constructor Details
#initialize(cocoon_type:, domain:, content: '', maturity: nil, protection: nil) ⇒ Cocoon
Returns a new instance of Cocoon.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 15 def initialize(cocoon_type:, domain:, content: '', maturity: nil, protection: nil) @id = SecureRandom.uuid @cocoon_type = cocoon_type.to_sym @domain = domain.to_sym @content = content @maturity = (maturity || 0.0).to_f.clamp(0.0, 1.0) @protection = (protection || PROTECTION_BY_TYPE.fetch(@cocoon_type, 0.7)).to_f.clamp(0.0, 1.0) @stage = :encapsulating @created_at = Time.now.utc advance_stage! end |
Instance Attribute Details
#cocoon_type ⇒ Object (readonly)
Returns the value of attribute cocoon_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def cocoon_type @cocoon_type end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.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/cocoon/helpers/cocoon.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def id @id end |
#maturity ⇒ Object (readonly)
Returns the value of attribute maturity.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def maturity @maturity end |
#protection ⇒ Object (readonly)
Returns the value of attribute protection.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def protection @protection end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 12 def stage @stage end |
Instance Method Details
#age_seconds ⇒ Object
57 58 59 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 57 def age_seconds (Time.now.utc - @created_at).round(2) end |
#emerge! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 35 def emerge! return { success: false, error: 'not ready', damaged: false } unless ready? @stage = :emerged { success: true, content: @content, damaged: false, maturity: @maturity } end |
#expose! ⇒ Object
42 43 44 45 46 47 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 42 def expose! damaged = premature? @maturity = (@maturity * PREMATURE_PENALTY).round(10) if damaged @stage = :emerged { success: true, content: @content, damaged: damaged, maturity: @maturity } end |
#gestate!(rate = MATURITY_RATE) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 27 def gestate!(rate = MATURITY_RATE) return self if @stage == :emerged @maturity = (@maturity + rate).clamp(0.0, 1.0).round(10) advance_stage! self end |
#premature? ⇒ Boolean
53 54 55 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 53 def premature? @stage != :ready && @stage != :emerged && @maturity < 1.0 end |
#ready? ⇒ Boolean
49 50 51 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 49 def ready? @maturity >= 1.0 || @stage == :ready end |
#to_h ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/extensions/agentic/homeostasis/cocoon/helpers/cocoon.rb', line 61 def to_h { id: @id, cocoon_type: @cocoon_type, domain: @domain, content: @content, maturity: @maturity.round(10), stage: @stage, protection: @protection.round(10), ready: ready?, premature: premature?, maturity_label: Constants.label_for(MATURITY_LABELS, @maturity), age_seconds: age_seconds, created_at: @created_at.iso8601 } end |