Class: Legion::Extensions::Agentic::Defense::Erosion::Helpers::Formation
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Defense::Erosion::Helpers::Formation
- Defined in:
- lib/legion/extensions/agentic/defense/erosion/helpers/formation.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.
-
#erosion_depth ⇒ Object
readonly
Returns the value of attribute erosion_depth.
-
#formation_id ⇒ Object
readonly
Returns the value of attribute formation_id.
-
#integrity ⇒ Object
readonly
Returns the value of attribute integrity.
-
#material_type ⇒ Object
readonly
Returns the value of attribute material_type.
-
#resistance ⇒ Object
readonly
Returns the value of attribute resistance.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #canyon? ⇒ Boolean
- #depth_label ⇒ Object
- #erode!(agent, force) ⇒ Object
-
#initialize(material_type:, domain:, content:, resistance: nil) ⇒ Formation
constructor
A new instance of Formation.
- #integrity_label ⇒ Object
- #pristine? ⇒ Boolean
- #resist!(amount = nil) ⇒ Object
- #to_h ⇒ Object
- #weathered? ⇒ Boolean
Constructor Details
#initialize(material_type:, domain:, content:, resistance: nil) ⇒ Formation
Returns a new instance of Formation.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 15 def initialize(material_type:, domain:, content:, resistance: nil, **) raise ArgumentError, "invalid material_type: #{material_type}" unless Constants::MATERIAL_TYPES.include?(material_type) @formation_id = SecureRandom.uuid @material_type = material_type @domain = domain @content = content @resistance = resistance || Constants::RESISTANCE.fetch(material_type) @integrity = 1.0 @erosion_depth = 0.0 @created_at = Time.now.utc @updated_at = Time.now.utc end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.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/erosion/helpers/formation.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def domain @domain end |
#erosion_depth ⇒ Object (readonly)
Returns the value of attribute erosion_depth.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def erosion_depth @erosion_depth end |
#formation_id ⇒ Object (readonly)
Returns the value of attribute formation_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def formation_id @formation_id end |
#integrity ⇒ Object (readonly)
Returns the value of attribute integrity.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def integrity @integrity end |
#material_type ⇒ Object (readonly)
Returns the value of attribute material_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def material_type @material_type end |
#resistance ⇒ Object (readonly)
Returns the value of attribute resistance.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def resistance @resistance end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 12 def updated_at @updated_at end |
Instance Method Details
#canyon? ⇒ Boolean
54 55 56 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 54 def canyon? @erosion_depth >= 0.7 end |
#depth_label ⇒ Object
69 70 71 72 73 74 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 69 def depth_label Constants::CHANNEL_DEPTH_LABELS.each do |range, label| return label if range.cover?(@erosion_depth) end :surface_scratch end |
#erode!(agent, force) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 29 def erode!(agent, force) raise ArgumentError, "invalid agent: #{agent}" unless Constants::EROSION_AGENTS.include?(agent) force = force.clamp(0.0, 1.0) effective_force = (force * (1.0 - @resistance)).round(10) @integrity = (@integrity - effective_force).clamp(0.0, 1.0).round(10) @erosion_depth = (@erosion_depth + effective_force).clamp(0.0, 1.0).round(10) @updated_at = Time.now.utc { agent: agent, force: force, effective_force: effective_force, integrity: @integrity, erosion_depth: @erosion_depth } end |
#integrity_label ⇒ Object
62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 62 def integrity_label Constants::FORMATION_LABELS.each do |range, label| return label if range.cover?(@integrity) end :ruins end |
#pristine? ⇒ Boolean
58 59 60 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 58 def pristine? @integrity >= 0.9 end |
#resist!(amount = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 42 def resist!(amount = nil) amount ||= @resistance * 0.1 amount = amount.clamp(0.0, 1.0) @integrity = (@integrity + amount).clamp(0.0, 1.0).round(10) @updated_at = Time.now.utc { integrity: @integrity, recovered: amount } end |
#to_h ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 76 def to_h { formation_id: @formation_id, material_type: @material_type, domain: @domain, content: @content, resistance: @resistance, integrity: @integrity, erosion_depth: @erosion_depth, integrity_label: integrity_label, depth_label: depth_label, weathered: weathered?, canyon: canyon?, pristine: pristine?, created_at: @created_at, updated_at: @updated_at } end |
#weathered? ⇒ Boolean
50 51 52 |
# File 'lib/legion/extensions/agentic/defense/erosion/helpers/formation.rb', line 50 def weathered? @integrity < 0.7 end |