Class: Legion::Extensions::Agentic::Homeostasis::Furnace::Helpers::Ore

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (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_atObject (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

#domainObject (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

#impurityObject

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_idObject (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_typeObject (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

#purityObject

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 48

def crude?
  purity < 0.3
end

#pure?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/legion/extensions/agentic/homeostasis/furnace/helpers/ore.rb', line 44

def pure?
  purity >= 0.8
end

#purity_labelObject



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_hObject



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