Class: Legion::Extensions::Agentic::Integration::Tapestry::Helpers::Thread
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Tapestry::Helpers::Thread
- Defined in:
- lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb
Constant Summary collapse
- COLOR_MAP =
{ experience: :gold, belief: :silver, memory: :blue, emotion: :crimson, narrative: :violet }.freeze
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#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.
-
#strength ⇒ Object
Returns the value of attribute strength.
-
#tapestry_id ⇒ Object
readonly
Returns the value of attribute tapestry_id.
-
#thread_type ⇒ Object
readonly
Returns the value of attribute thread_type.
Instance Method Summary collapse
- #fray!(rate: Constants::FRAY_RATE) ⇒ Object
-
#initialize(thread_type:, domain:, content:, strength: nil, color: nil) ⇒ Thread
constructor
A new instance of Thread.
- #loose? ⇒ Boolean
- #reinforce!(rate: Constants::TENSION_RATE) ⇒ Object
- #snap? ⇒ Boolean
- #taut? ⇒ Boolean
- #thread_integrity ⇒ Object
- #to_h ⇒ Object
- #unwoven! ⇒ Object
- #woven? ⇒ Boolean
- #woven_into!(tapestry_id) ⇒ Object
Constructor Details
#initialize(thread_type:, domain:, content:, strength: nil, color: nil) ⇒ Thread
Returns a new instance of Thread.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 22 def initialize(thread_type:, domain:, content:, strength: nil, color: nil) validate_thread_type!(thread_type) @id = SecureRandom.uuid @thread_type = thread_type.to_sym @domain = domain.to_sym @content = content.to_s @strength = (strength || 0.5).to_f.clamp(0.0, 1.0).round(10) @color = (color || default_color(thread_type)).to_sym @created_at = Time.now.utc @tapestry_id = nil end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def color @color end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def id @id end |
#strength ⇒ Object
Returns the value of attribute strength.
12 13 14 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 12 def strength @strength end |
#tapestry_id ⇒ Object (readonly)
Returns the value of attribute tapestry_id.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def tapestry_id @tapestry_id end |
#thread_type ⇒ Object (readonly)
Returns the value of attribute thread_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 10 def thread_type @thread_type end |
Instance Method Details
#fray!(rate: Constants::FRAY_RATE) ⇒ Object
50 51 52 53 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 50 def fray!(rate: Constants::FRAY_RATE) @strength = (@strength - rate.abs).clamp(0.0, 1.0).round(10) self end |
#loose? ⇒ Boolean
67 68 69 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 67 def loose? @tapestry_id.nil? end |
#reinforce!(rate: Constants::TENSION_RATE) ⇒ Object
45 46 47 48 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 45 def reinforce!(rate: Constants::TENSION_RATE) @strength = (@strength + rate.abs).clamp(0.0, 1.0).round(10) self end |
#snap? ⇒ Boolean
55 56 57 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 55 def snap? @strength <= 0.0 end |
#taut? ⇒ Boolean
59 60 61 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 59 def taut? @strength >= 0.9 end |
#thread_integrity ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 71 def thread_integrity Constants.label_for(Constants::INTEGRITY_LABELS, @strength) end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 75 def to_h { id: @id, thread_type: @thread_type, domain: @domain, content: @content, strength: @strength, color: @color, thread_integrity: thread_integrity, woven: woven?, loose: loose?, snap: snap?, taut: taut?, tapestry_id: @tapestry_id, created_at: @created_at } end |
#unwoven! ⇒ Object
40 41 42 43 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 40 def unwoven! @tapestry_id = nil self end |
#woven? ⇒ Boolean
63 64 65 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 63 def woven? !@tapestry_id.nil? end |
#woven_into!(tapestry_id) ⇒ Object
35 36 37 38 |
# File 'lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb', line 35 def woven_into!(tapestry_id) @tapestry_id = tapestry_id self end |