Class: Legion::Extensions::Agentic::Learning::Chrysalis::Helpers::Chrysalis
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Chrysalis::Helpers::Chrysalis
- Defined in:
- lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb
Instance Attribute Summary collapse
-
#beauty ⇒ Object
readonly
Returns the value of attribute beauty.
-
#chrysalis_type ⇒ Object
readonly
Returns the value of attribute chrysalis_type.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#protection ⇒ Object
readonly
Returns the value of attribute protection.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
-
#transformation_progress ⇒ Object
readonly
Returns the value of attribute transformation_progress.
Instance Method Summary collapse
- #beauty_label ⇒ Object
- #butterfly? ⇒ Boolean
- #cocoon! ⇒ Object
- #cocooned? ⇒ Boolean
- #decay_protection! ⇒ Object
- #disturb!(force) ⇒ Object
- #emerge!(force: false) ⇒ Object
-
#initialize(chrysalis_type:, content:) ⇒ Chrysalis
constructor
A new instance of Chrysalis.
- #premature? ⇒ Boolean
- #spin! ⇒ Object
- #stage_label ⇒ Object
- #to_h ⇒ Object
- #transform!(rate = Helpers::Constants::TRANSFORMATION_RATE) ⇒ Object
- #transforming? ⇒ Boolean
Constructor Details
#initialize(chrysalis_type:, content:) ⇒ Chrysalis
Returns a new instance of Chrysalis.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 15 def initialize(chrysalis_type:, content:, **) @id = SecureRandom.uuid @chrysalis_type = chrysalis_type.to_sym @content = content.to_s @stage = :larva @transformation_progress = 0.0 @protection = 0.8 @beauty = 0.0 @created_at = Time.now.utc @premature = false end |
Instance Attribute Details
#beauty ⇒ Object (readonly)
Returns the value of attribute beauty.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def beauty @beauty end |
#chrysalis_type ⇒ Object (readonly)
Returns the value of attribute chrysalis_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def chrysalis_type @chrysalis_type end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.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/learning/chrysalis/helpers/chrysalis.rb', line 12 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def id @id end |
#protection ⇒ Object (readonly)
Returns the value of attribute protection.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def protection @protection end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def stage @stage end |
#transformation_progress ⇒ Object (readonly)
Returns the value of attribute transformation_progress.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 12 def transformation_progress @transformation_progress end |
Instance Method Details
#beauty_label ⇒ Object
93 94 95 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 93 def beauty_label Helpers::Constants.label_for(Helpers::Constants::BEAUTY_LABELS, @beauty) end |
#butterfly? ⇒ Boolean
73 74 75 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 73 def butterfly? @stage == :butterfly end |
#cocoon! ⇒ Object
34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 34 def cocoon! raise ArgumentError, "must be :spinning to cocoon, currently #{@stage}" unless @stage == :spinning @stage = :cocooned true end |
#cocooned? ⇒ Boolean
77 78 79 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 77 def cocooned? @stage == :cocooned end |
#decay_protection! ⇒ Object
64 65 66 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 64 def decay_protection! @protection = (@protection - Helpers::Constants::PROTECTION_DECAY).clamp(0.0, 1.0).round(10) end |
#disturb!(force) ⇒ Object
68 69 70 71 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 68 def disturb!(force) @protection = (@protection - force.to_f).clamp(0.0, 1.0).round(10) emerge!(force: true) if @protection <= 0 && %i[cocooned transforming].include?(@stage) end |
#emerge!(force: false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 50 def emerge!(force: false) if @transformation_progress >= Helpers::Constants::EMERGENCE_THRESHOLD @stage = :butterfly @beauty = 1.0 elsif force @premature = true @stage = :butterfly @beauty = (@beauty - Helpers::Constants::PREMATURE_PENALTY).clamp(0.0, 1.0).round(10) else return false end true end |
#premature? ⇒ Boolean
85 86 87 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 85 def premature? butterfly? && @beauty < 0.5 end |
#spin! ⇒ Object
27 28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 27 def spin! raise ArgumentError, "must be :larva to spin, currently #{@stage}" unless @stage == :larva @stage = :spinning true end |
#stage_label ⇒ Object
89 90 91 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 89 def stage_label Helpers::Constants.label_for(Helpers::Constants::STAGE_LABELS, @transformation_progress) end |
#to_h ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 97 def to_h { id: @id, chrysalis_type: @chrysalis_type, content: @content, stage: @stage, transformation_progress: @transformation_progress, protection: @protection, beauty: @beauty, stage_label: stage_label, beauty_label: beauty_label, premature: @premature, created_at: @created_at } end |
#transform!(rate = Helpers::Constants::TRANSFORMATION_RATE) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 41 def transform!(rate = Helpers::Constants::TRANSFORMATION_RATE) return false if @stage == :butterfly @transformation_progress = (@transformation_progress + rate).clamp(0.0, 1.0).round(10) @beauty = (@transformation_progress * 0.9).clamp(0.0, 1.0).round(10) update_stage_from_progress! true end |
#transforming? ⇒ Boolean
81 82 83 |
# File 'lib/legion/extensions/agentic/learning/chrysalis/helpers/chrysalis.rb', line 81 def transforming? @stage == :transforming end |