Class: Legion::Extensions::Agentic::Homeostasis::Tide::Helpers::TidalPool
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Tide::Helpers::TidalPool
- Defined in:
- lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#evaporation_count ⇒ Object
readonly
Returns the value of attribute evaporation_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#deposit(item) ⇒ Object
Deposit an idea item into the pool; silently drops if full.
-
#depth ⇒ Object
Depth as a fraction of capacity: item_count / capacity.
- #empty? ⇒ Boolean
-
#evaporate!(rate = Constants::POOL_EVAPORATION_RATE) ⇒ Object
Apply evaporation: remove a proportion of items (oldest first).
- #full? ⇒ Boolean
-
#harvest! ⇒ Object
Harvest all items from the pool, clearing it; returns the harvested items.
-
#initialize(domain:, capacity: 20) ⇒ TidalPool
constructor
A new instance of TidalPool.
- #items ⇒ Object
- #size ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(domain:, capacity: 20) ⇒ TidalPool
Returns a new instance of TidalPool.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 12 def initialize(domain:, capacity: 20) raise ArgumentError, 'capacity must be positive' unless capacity.positive? @id = SecureRandom.uuid @domain = domain.to_s @capacity = capacity @items = [] @evaporation_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 10 def capacity @capacity end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 10 def domain @domain end |
#evaporation_count ⇒ Object (readonly)
Returns the value of attribute evaporation_count.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 10 def evaporation_count @evaporation_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 10 def id @id end |
Instance Method Details
#deposit(item) ⇒ Object
Deposit an idea item into the pool; silently drops if full
24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 24 def deposit(item) return false if full? @items << { content: item, deposited_at: Time.now.utc, id: SecureRandom.uuid } true end |
#depth ⇒ Object
Depth as a fraction of capacity: item_count / capacity
56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 56 def depth return 0.0 if @capacity.zero? (@items.size.to_f / @capacity).round(10) end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 47 def empty? @items.empty? end |
#evaporate!(rate = Constants::POOL_EVAPORATION_RATE) ⇒ Object
Apply evaporation: remove a proportion of items (oldest first)
39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 39 def evaporate!(rate = Constants::POOL_EVAPORATION_RATE) clamped_rate = rate.clamp(0.0, 1.0) count_to_remove = (@items.size * clamped_rate).ceil removed = @items.shift(count_to_remove) @evaporation_count += removed.size removed.size end |
#full? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 51 def full? @items.size >= @capacity end |
#harvest! ⇒ Object
Harvest all items from the pool, clearing it; returns the harvested items
32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 32 def harvest! harvested = @items.dup @items.clear harvested end |
#items ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 62 def items @items.dup end |
#size ⇒ Object
66 67 68 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 66 def size @items.size end |
#to_h ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/legion/extensions/agentic/homeostasis/tide/helpers/tidal_pool.rb', line 70 def to_h { id: @id, domain: @domain, capacity: @capacity, size: @items.size, depth: depth, evaporation_count: @evaporation_count, created_at: @created_at } end |