Class: Legion::Extensions::Agentic::Defense::Quicksilver::Helpers::Droplet
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Quicksilver::Helpers::Droplet
- Defined in:
- lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb
Constant Summary collapse
- FORM_FLUIDITY =
{ liquid: 0.9, droplet: 0.8, bead: 0.7, stream: 0.6, pool: 0.3 }.freeze
Instance Attribute Summary collapse
-
#captured ⇒ Object
readonly
Returns the value of attribute captured.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#fluidity ⇒ Object
readonly
Returns the value of attribute fluidity.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#mass ⇒ Object
readonly
Returns the value of attribute mass.
-
#surface ⇒ Object
readonly
Returns the value of attribute surface.
Instance Method Summary collapse
- #capture! ⇒ Object
- #cohesion_label ⇒ Object
- #elusive? ⇒ Boolean
- #evaporate! ⇒ Object
- #fluidity_label ⇒ Object
-
#initialize(form:, content:, mass: 0.3, fluidity: Constants::FLUIDITY_BASE, surface: :glass) ⇒ Droplet
constructor
A new instance of Droplet.
- #merge!(other_droplet) ⇒ Object
- #release! ⇒ Object
- #shift_form!(new_form) ⇒ Object
- #split! ⇒ Object
- #stable? ⇒ Boolean
- #to_h ⇒ Object
- #vanishing? ⇒ Boolean
Constructor Details
#initialize(form:, content:, mass: 0.3, fluidity: Constants::FLUIDITY_BASE, surface: :glass) ⇒ Droplet
Returns a new instance of Droplet.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 22 def initialize(form:, content:, mass: 0.3, fluidity: Constants::FLUIDITY_BASE, surface: :glass) raise ArgumentError, "invalid form: #{form}" unless Constants::FORM_TYPES.include?(form) raise ArgumentError, "invalid surface: #{surface}" unless Constants::SURFACE_TYPES.include?(surface) @id = SecureRandom.uuid @form = form @content = content @mass = mass.clamp(0.0, 1.0) @fluidity = fluidity.clamp(0.0, 1.0) @surface = surface @captured = false @created_at = Time.now.utc end |
Instance Attribute Details
#captured ⇒ Object (readonly)
Returns the value of attribute captured.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def captured @captured end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def created_at @created_at end |
#fluidity ⇒ Object (readonly)
Returns the value of attribute fluidity.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def fluidity @fluidity end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def form @form end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def id @id end |
#mass ⇒ Object (readonly)
Returns the value of attribute mass.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def mass @mass end |
#surface ⇒ Object (readonly)
Returns the value of attribute surface.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 12 def surface @surface end |
Instance Method Details
#capture! ⇒ Object
66 67 68 69 70 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 66 def capture! @captured = true @fluidity = (@fluidity / 2.0).round(10) self end |
#cohesion_label ⇒ Object
95 96 97 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 95 def cohesion_label Constants.label_for(Constants::COHESION_LABELS, @mass) end |
#elusive? ⇒ Boolean
83 84 85 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 83 def elusive? @fluidity >= 0.7 && !@captured end |
#evaporate! ⇒ Object
78 79 80 81 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 78 def evaporate! @mass = (@mass - Constants::EVAPORATION_RATE).clamp(0.0, 1.0).round(10) self end |
#fluidity_label ⇒ Object
99 100 101 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 99 def fluidity_label Constants.label_for(Constants::FLUIDITY_LABELS, @fluidity) end |
#merge!(other_droplet) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 44 def merge!(other_droplet) @mass = (@mass + other_droplet.mass + Constants::COALESCENCE_BONUS).clamp(0.0, 1.0) @form = @mass >= other_droplet.mass ? @form : other_droplet.form @fluidity = ((@fluidity + other_droplet.fluidity) / 2.0).round(10) self end |
#release! ⇒ Object
72 73 74 75 76 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 72 def release! @captured = false @fluidity = (@fluidity * 2.0).clamp(0.0, 1.0) self end |
#shift_form!(new_form) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 36 def shift_form!(new_form) raise ArgumentError, "invalid form: #{new_form}" unless Constants::FORM_TYPES.include?(new_form) @form = new_form @fluidity = FORM_FLUIDITY.fetch(new_form, Constants::FLUIDITY_BASE).clamp(0.0, 1.0) self end |
#split! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 51 def split! return nil if @mass <= 0.2 half_mass = (@mass / 2.0).round(10) @mass = half_mass self.class.new( form: @form, content: @content, mass: half_mass, fluidity: @fluidity, surface: @surface ) end |
#stable? ⇒ Boolean
87 88 89 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 87 def stable? @fluidity < 0.4 || @captured end |
#to_h ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 103 def to_h { id: @id, form: @form, content: @content, mass: @mass.round(10), fluidity: @fluidity.round(10), surface: @surface, captured: @captured, elusive: elusive?, stable: stable?, vanishing: vanishing?, cohesion: cohesion_label, fluidity_lbl: fluidity_label, created_at: @created_at } end |
#vanishing? ⇒ Boolean
91 92 93 |
# File 'lib/legion/extensions/agentic/defense/quicksilver/helpers/droplet.rb', line 91 def vanishing? @mass < 0.1 end |