Class: Legion::Extensions::Agentic::Homeostasis::Hourglass::Helpers::Grain
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Hourglass::Helpers::Grain
- Defined in:
- lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb
Instance Attribute Summary collapse
-
#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.
-
#grain_type ⇒ Object
readonly
Returns the value of attribute grain_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#dust? ⇒ Boolean
A grain is dust when its weight is below 0.05 — nearly weightless.
-
#erode!(rate = 0.01) ⇒ Object
Erode the grain — reduce weight by rate, floors at 0.0.
-
#heavy? ⇒ Boolean
A grain is heavy when its weight is above 0.75 — substantial cognitive unit.
-
#initialize(grain_type:, domain: nil, content: nil, weight: 1.0) ⇒ Grain
constructor
A new instance of Grain.
-
#solidify!(rate = 0.01) ⇒ Object
Solidify the grain — increase weight by rate, caps at 1.0.
- #to_h ⇒ Object
Constructor Details
#initialize(grain_type:, domain: nil, content: nil, weight: 1.0) ⇒ Grain
Returns a new instance of Grain.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 12 def initialize(grain_type:, domain: nil, content: nil, weight: 1.0) raise ArgumentError, "unknown grain_type: #{grain_type}" unless Constants::GRAIN_TYPES.include?(grain_type.to_sym) raise ArgumentError, 'weight must be between 0.0 and 1.0' unless (0.0..1.0).cover?(weight.to_f) @id = SecureRandom.uuid @grain_type = grain_type.to_sym @domain = domain&.to_s @content = content @weight = weight.to_f.clamp(0.0, 1.0).round(10) @created_at = Time.now.utc end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.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/homeostasis/hourglass/helpers/grain.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/homeostasis/hourglass/helpers/grain.rb', line 10 def domain @domain end |
#grain_type ⇒ Object (readonly)
Returns the value of attribute grain_type.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 10 def grain_type @grain_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 10 def id @id end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
10 11 12 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 10 def weight @weight end |
Instance Method Details
#dust? ⇒ Boolean
A grain is dust when its weight is below 0.05 — nearly weightless
37 38 39 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 37 def dust? @weight < 0.05 end |
#erode!(rate = 0.01) ⇒ Object
Erode the grain — reduce weight by rate, floors at 0.0
25 26 27 28 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 25 def erode!(rate = 0.01) @weight = (@weight - rate.to_f.clamp(0.0, 1.0)).clamp(0.0, 1.0).round(10) self end |
#heavy? ⇒ Boolean
A grain is heavy when its weight is above 0.75 — substantial cognitive unit
42 43 44 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 42 def heavy? @weight > 0.75 end |
#solidify!(rate = 0.01) ⇒ Object
Solidify the grain — increase weight by rate, caps at 1.0
31 32 33 34 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 31 def solidify!(rate = 0.01) @weight = (@weight + rate.to_f.clamp(0.0, 1.0)).clamp(0.0, 1.0).round(10) self end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/homeostasis/hourglass/helpers/grain.rb', line 46 def to_h { id: @id, grain_type: @grain_type, domain: @domain, content: @content, weight: @weight, created_at: @created_at, dust: dust?, heavy: heavy? } end |