Class: Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::Ore
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::Ore
- Defined in:
- lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.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.
-
#impurity ⇒ Object
Returns the value of attribute impurity.
-
#ore_id ⇒ Object
readonly
Returns the value of attribute ore_id.
-
#ore_type ⇒ Object
readonly
Returns the value of attribute ore_type.
-
#purity ⇒ Object
Returns the value of attribute purity.
Instance Method Summary collapse
- #contaminate!(rate = Constants::COOL_RATE) ⇒ Object
- #crude? ⇒ Boolean
-
#initialize(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) ⇒ Ore
constructor
A new instance of Ore.
- #pure? ⇒ Boolean
- #purity_label ⇒ Object
- #refine!(rate = Constants::HEAT_RATE) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) ⇒ Ore
Returns a new instance of Ore.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 15 def initialize(ore_type:, domain:, content:, purity: 0.5, impurity: nil, ore_id: nil) unless Constants::ORE_TYPES.include?(ore_type) raise ArgumentError, "unknown ore_type: #{ore_type.inspect}; " \ "must be one of #{Constants::ORE_TYPES.inspect}" end @ore_id = ore_id || SecureRandom.uuid @ore_type = ore_type @domain = domain @content = content @purity = purity.clamp(0.0, 1.0) @impurity = (impurity || (1.0 - @purity)).clamp(0.0, 1.0) @created_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/homeostasis/furnace/helpers/ore.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/homeostasis/furnace/helpers/ore.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/homeostasis/furnace/helpers/ore.rb', line 12 def domain @domain end |
#impurity ⇒ Object
Returns the value of attribute impurity.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 13 def impurity @impurity end |
#ore_id ⇒ Object (readonly)
Returns the value of attribute ore_id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 12 def ore_id @ore_id end |
#ore_type ⇒ Object (readonly)
Returns the value of attribute ore_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 12 def ore_type @ore_type end |
#purity ⇒ Object
Returns the value of attribute purity.
13 14 15 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 13 def purity @purity end |
Instance Method Details
#contaminate!(rate = Constants::COOL_RATE) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 37 def contaminate!(rate = Constants::COOL_RATE) delta = rate.clamp(0.0, 1.0) self.purity = (purity - delta).clamp(0.0, 1.0) self.impurity = (impurity + delta).clamp(0.0, 1.0) self end |
#crude? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 48 def crude? purity < 0.3 end |
#pure? ⇒ Boolean
44 45 46 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 44 def pure? purity >= 0.8 end |
#purity_label ⇒ Object
52 53 54 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 52 def purity_label Constants.label_for(Constants::PURITY_LABELS, purity) end |
#refine!(rate = Constants::HEAT_RATE) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 30 def refine!(rate = Constants::HEAT_RATE) delta = rate.clamp(0.0, 1.0) self.purity = (purity + delta).clamp(0.0, 1.0) self.impurity = (impurity - delta).clamp(0.0, 1.0) self end |
#to_h ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 56 def to_h { ore_id: ore_id, ore_type: ore_type, domain: domain, content: content, purity: purity.round(10), impurity: impurity.round(10), pure: pure?, crude: crude?, label: purity_label, created_at: created_at } end |