Class: Legion::Extensions::Agentic::Integration::Mycelium::Helpers::MycelialNode
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Integration::Mycelium::Helpers::MycelialNode
- Defined in:
- lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb
Instance Attribute Summary collapse
-
#connections_count ⇒ Object
Returns the value of attribute connections_count.
-
#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.
-
#node_type ⇒ Object
readonly
Returns the value of attribute node_type.
-
#nutrient_level ⇒ Object
Returns the value of attribute nutrient_level.
Instance Method Summary collapse
- #absorb!(amount) ⇒ Object
- #deplete!(amount) ⇒ Object
- #fruiting_ready? ⇒ Boolean
-
#initialize(node_type:, domain:, content:, nutrient_level: 0.5) ⇒ MycelialNode
constructor
A new instance of MycelialNode.
- #starving? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(node_type:, domain:, content:, nutrient_level: 0.5) ⇒ MycelialNode
Returns a new instance of MycelialNode.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 13 def initialize(node_type:, domain:, content:, nutrient_level: 0.5) validate_type!(node_type) @id = SecureRandom.uuid @node_type = node_type.to_sym @domain = domain.to_sym @content = content.to_s @nutrient_level = nutrient_level.to_f.clamp(0.0, 1.0).round(10) @connections_count = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#connections_count ⇒ Object
Returns the value of attribute connections_count.
11 12 13 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 11 def connections_count @connections_count end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.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/mycelium/helpers/mycelial_node.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/mycelium/helpers/mycelial_node.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/mycelium/helpers/mycelial_node.rb', line 10 def id @id end |
#node_type ⇒ Object (readonly)
Returns the value of attribute node_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 10 def node_type @node_type end |
#nutrient_level ⇒ Object
Returns the value of attribute nutrient_level.
11 12 13 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 11 def nutrient_level @nutrient_level end |
Instance Method Details
#absorb!(amount) ⇒ Object
25 26 27 28 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 25 def absorb!(amount) @nutrient_level = (@nutrient_level + amount.abs).clamp(0.0, 1.0).round(10) self end |
#deplete!(amount) ⇒ Object
30 31 32 33 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 30 def deplete!(amount) @nutrient_level = (@nutrient_level - amount.abs).clamp(0.0, 1.0).round(10) self end |
#fruiting_ready? ⇒ Boolean
35 36 37 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 35 def fruiting_ready? @nutrient_level >= Constants::FRUITING_THRESHOLD end |
#starving? ⇒ Boolean
39 40 41 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 39 def starving? @nutrient_level < 0.1 end |
#to_h ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb', line 43 def to_h { id: @id, node_type: @node_type, domain: @domain, content: @content, nutrient_level: @nutrient_level, connections_count: @connections_count, fruiting_ready: fruiting_ready?, starving: starving?, created_at: @created_at } end |