Class: Legion::Extensions::Agentic::Self::Anchor::Helpers::Chain
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Anchor::Helpers::Chain
- Defined in:
- lib/legion/extensions/agentic/self/anchor/helpers/chain.rb
Instance Attribute Summary collapse
-
#anchor_id ⇒ Object
readonly
Returns the value of attribute anchor_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#flexibility ⇒ Object
Returns the value of attribute flexibility.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#material ⇒ Object
readonly
Returns the value of attribute material.
Instance Method Summary collapse
- #broken? ⇒ Boolean
- #elastic? ⇒ Boolean
- #extend!(amount: 0.1) ⇒ Object
- #flexibility_label ⇒ Object
-
#initialize(anchor_id:, material: :steel, length: nil, flexibility: nil) ⇒ Chain
constructor
A new instance of Chain.
- #long? ⇒ Boolean
- #rigid? ⇒ Boolean
- #short? ⇒ Boolean
- #shorten!(amount: 0.1) ⇒ Object
- #to_h ⇒ Object
- #wear!(rate: 0.05) ⇒ Object
Constructor Details
#initialize(anchor_id:, material: :steel, length: nil, flexibility: nil) ⇒ Chain
Returns a new instance of Chain.
13 14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 13 def initialize(anchor_id:, material: :steel, length: nil, flexibility: nil) validate_material!(material) @id = SecureRandom.uuid @anchor_id = anchor_id @material = material.to_sym @length = (length || 0.5).to_f.clamp(0.0, 1.0).round(10) @flexibility = (flexibility || material_flexibility).to_f.clamp(0.0, 1.0).round(10) @created_at = Time.now.utc end |
Instance Attribute Details
#anchor_id ⇒ Object (readonly)
Returns the value of attribute anchor_id.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 10 def anchor_id @anchor_id end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 10 def created_at @created_at end |
#flexibility ⇒ Object
Returns the value of attribute flexibility.
11 12 13 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 11 def flexibility @flexibility end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 10 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
11 12 13 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 11 def length @length end |
#material ⇒ Object (readonly)
Returns the value of attribute material.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 10 def material @material end |
Instance Method Details
#broken? ⇒ Boolean
35 36 37 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 35 def broken? @flexibility < Constants::BREAK_THRESHOLD end |
#elastic? ⇒ Boolean
39 40 41 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 39 def elastic? @flexibility >= 0.8 end |
#extend!(amount: 0.1) ⇒ Object
23 24 25 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 23 def extend!(amount: 0.1) @length = (@length + amount.abs).clamp(0.0, 1.0).round(10) end |
#flexibility_label ⇒ Object
55 56 57 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 55 def flexibility_label Constants.label_for(Constants::FLEXIBILITY_LABELS, @flexibility) end |
#long? ⇒ Boolean
51 52 53 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 51 def long? @length >= 0.7 end |
#rigid? ⇒ Boolean
43 44 45 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 43 def rigid? @flexibility < 0.2 end |
#short? ⇒ Boolean
47 48 49 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 47 def short? @length < 0.3 end |
#shorten!(amount: 0.1) ⇒ Object
27 28 29 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 27 def shorten!(amount: 0.1) @length = (@length - amount.abs).clamp(0.0, 1.0).round(10) end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 59 def to_h { id: @id, anchor_id: @anchor_id, material: @material, length: @length, flexibility: @flexibility, flexibility_label: flexibility_label, broken: broken?, elastic: elastic?, created_at: @created_at } end |
#wear!(rate: 0.05) ⇒ Object
31 32 33 |
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 31 def wear!(rate: 0.05) @flexibility = (@flexibility - rate.abs).clamp(0.0, 1.0).round(10) end |