Class: Legion::Extensions::Agentic::Inference::Magnet::Helpers::Field
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Magnet::Helpers::Field
- Defined in:
- lib/legion/extensions/agentic/inference/magnet/helpers/field.rb
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Returns the value of attribute alignment.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#flux_density ⇒ Object
readonly
Returns the value of attribute flux_density.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pole_ids ⇒ Object
readonly
Returns the value of attribute pole_ids.
Instance Method Summary collapse
- #add_pole(pole_id) ⇒ Object
- #alignment_label ⇒ Object
- #calculate_alignment!(poles) ⇒ Object
- #chaotic? ⇒ Boolean
- #coherent? ⇒ Boolean
-
#initialize(name:) ⇒ Field
constructor
A new instance of Field.
- #pole_count ⇒ Object
- #remove_pole(pole_id) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:) ⇒ Field
Returns a new instance of Field.
14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 14 def initialize(name:) @id = SecureRandom.uuid @name = name @pole_ids = [] @alignment = 0.0 @flux_density = 0.0 @created_at = Time.now.utc end |
Instance Attribute Details
#alignment ⇒ Object (readonly)
Returns the value of attribute alignment.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def alignment @alignment end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def created_at @created_at end |
#flux_density ⇒ Object (readonly)
Returns the value of attribute flux_density.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def flux_density @flux_density end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def name @name end |
#pole_ids ⇒ Object (readonly)
Returns the value of attribute pole_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 12 def pole_ids @pole_ids end |
Instance Method Details
#add_pole(pole_id) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 23 def add_pole(pole_id) return false if @pole_ids.include?(pole_id) @pole_ids << pole_id true end |
#alignment_label ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 52 def alignment_label Constants.label_for(Constants::ALIGNMENT_LABELS, @alignment) end |
#calculate_alignment!(poles) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 35 def calculate_alignment!(poles) field_poles = poles.values.select { |p| @pole_ids.include?(p.id) } return self if field_poles.empty? @flux_density = field_poles.sum(&:strength) / field_poles.size.to_f @alignment = compute_alignment(field_poles).round(10) self end |
#chaotic? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 48 def chaotic? @alignment < 0.2 end |
#coherent? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 44 def coherent? @alignment >= 0.6 end |
#pole_count ⇒ Object
56 57 58 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 56 def pole_count @pole_ids.size end |
#remove_pole(pole_id) ⇒ Object
30 31 32 33 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 30 def remove_pole(pole_id) removed = @pole_ids.delete(pole_id) !removed.nil? end |
#to_h ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/inference/magnet/helpers/field.rb', line 60 def to_h { id: @id, name: @name, pole_ids: @pole_ids.dup, alignment: @alignment, flux_density: @flux_density, pole_count: pole_count, coherent: coherent?, chaotic: chaotic?, alignment_label: alignment_label, created_at: @created_at } end |