Class: Legion::Extensions::Agentic::Self::Anchor::Helpers::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/anchor/helpers/chain.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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_atObject (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

#flexibilityObject

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

#idObject (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

#lengthObject

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

#materialObject (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

Returns:

  • (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

Returns:

  • (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_labelObject



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

Returns:

  • (Boolean)


51
52
53
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 51

def long?
  @length >= 0.7
end

#rigid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/self/anchor/helpers/chain.rb', line 43

def rigid?
  @flexibility < 0.2
end

#short?Boolean

Returns:

  • (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_hObject



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