Class: Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::Crucible
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::Crucible
- Defined in:
- lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#crucible_id ⇒ Object
readonly
Returns the value of attribute crucible_id.
-
#ore_ids ⇒ Object
readonly
Returns the value of attribute ore_ids.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
Instance Method Summary collapse
- #cool!(rate = Constants::COOL_RATE) ⇒ Object
- #full? ⇒ Boolean
- #heat!(rate = Constants::HEAT_RATE) ⇒ Object
-
#initialize(capacity: 10, crucible_id: nil, temperature: 0.0) ⇒ Crucible
constructor
A new instance of Crucible.
- #load_ore(ore_id) ⇒ Object
- #optimal? ⇒ Boolean
- #overheated? ⇒ Boolean
- #smelt!(ore_store, alloy_type: nil) ⇒ Object
- #temperature_label ⇒ Object
- #to_h ⇒ Object
- #unload_ore(ore_id) ⇒ Object
Constructor Details
#initialize(capacity: 10, crucible_id: nil, temperature: 0.0) ⇒ Crucible
Returns a new instance of Crucible.
15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 15 def initialize(capacity: 10, crucible_id: nil, temperature: 0.0) @crucible_id = crucible_id || SecureRandom.uuid @capacity = capacity.clamp(1, 100) @temperature = temperature.clamp(0.0, 1.0) @ore_ids = [] @created_at = Time.now.utc end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 12 def capacity @capacity end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 12 def created_at @created_at end |
#crucible_id ⇒ Object (readonly)
Returns the value of attribute crucible_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 12 def crucible_id @crucible_id end |
#ore_ids ⇒ Object (readonly)
Returns the value of attribute ore_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 12 def ore_ids @ore_ids end |
#temperature ⇒ Object
Returns the value of attribute temperature.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 13 def temperature @temperature end |
Instance Method Details
#cool!(rate = Constants::COOL_RATE) ⇒ Object
28 29 30 31 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 28 def cool!(rate = Constants::COOL_RATE) self.temperature = (temperature - rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) self end |
#full? ⇒ Boolean
70 71 72 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 70 def full? ore_ids.size >= capacity end |
#heat!(rate = Constants::HEAT_RATE) ⇒ Object
23 24 25 26 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 23 def heat!(rate = Constants::HEAT_RATE) self.temperature = (temperature + rate.clamp(0.0, 1.0)).clamp(0.0, 1.0) self end |
#load_ore(ore_id) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 33 def load_ore(ore_id) return { loaded: false, reason: :at_capacity } if ore_ids.size >= capacity return { loaded: false, reason: :already_loaded } if ore_ids.include?(ore_id) ore_ids << ore_id { loaded: true, ore_id: ore_id, count: ore_ids.size } end |
#optimal? ⇒ Boolean
62 63 64 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 62 def optimal? temperature >= Constants::SMELT_THRESHOLD && temperature < Constants::DESTROY_THRESHOLD end |
#overheated? ⇒ Boolean
58 59 60 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 58 def overheated? temperature >= Constants::DESTROY_THRESHOLD end |
#smelt!(ore_store, alloy_type: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 46 def smelt!(ore_store, alloy_type: nil) return { smelted: false, reason: :temperature_too_low } unless temperature >= Constants::SMELT_THRESHOLD return { smelted: false, reason: :no_ores } if ore_ids.empty? ores = ore_ids.filter_map { |id| ore_store[id] } return { smelted: false, reason: :no_ores_found } if ores.empty? alloy = build_alloy(ores, alloy_type) ore_ids.clear { smelted: true, alloy: alloy } end |
#temperature_label ⇒ Object
66 67 68 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 66 def temperature_label Constants.label_for(Constants::TEMPERATURE_LABELS, temperature) end |
#to_h ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 74 def to_h { crucible_id: crucible_id, temperature: temperature.round(10), capacity: capacity, ore_count: ore_ids.size, ore_ids: ore_ids.dup, overheated: overheated?, optimal: optimal?, temperature_label: temperature_label, created_at: created_at } end |
#unload_ore(ore_id) ⇒ Object
41 42 43 44 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/crucible.rb', line 41 def unload_ore(ore_id) removed = ore_ids.delete(ore_id) { unloaded: removed ? true : false, ore_id: ore_id, count: ore_ids.size } end |