Class: Legion::Extensions::Agentic::Homeostasis::FossilFuel::Helpers::Combustion

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reserve_id:, fuel_amount:, grade: :crude, quality: 0.5) ⇒ Combustion

Returns a new instance of Combustion.



13
14
15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 13

def initialize(reserve_id:, fuel_amount:, grade: :crude, quality: 0.5)
  validate_grade!(grade)
  @id              = SecureRandom.uuid
  @reserve_id      = reserve_id
  @fuel_amount     = fuel_amount.to_f.clamp(0.0, 1.0).round(10)
  @grade           = grade.to_sym
  @energy_released = calculate_energy(fuel_amount, quality)
  @burned_at       = Time.now.utc
end

Instance Attribute Details

#burned_atObject (readonly)

Returns the value of attribute burned_at.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def burned_at
  @burned_at
end

#energy_releasedObject (readonly)

Returns the value of attribute energy_released.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def energy_released
  @energy_released
end

#fuel_amountObject (readonly)

Returns the value of attribute fuel_amount.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def fuel_amount
  @fuel_amount
end

#gradeObject (readonly)

Returns the value of attribute grade.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def grade
  @grade
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def id
  @id
end

#reserve_idObject (readonly)

Returns the value of attribute reserve_id.



10
11
12
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 10

def reserve_id
  @reserve_id
end

Instance Method Details

#efficient?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 23

def efficient?
  @energy_released > (@fuel_amount * 0.7)
end

#energy_labelObject



31
32
33
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 31

def energy_label
  Constants.label_for(Constants::ENERGY_LABELS, @energy_released)
end

#to_hObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 35

def to_h
  {
    id:              @id,
    reserve_id:      @reserve_id,
    fuel_amount:     @fuel_amount,
    grade:           @grade,
    energy_released: @energy_released,
    energy_label:    energy_label,
    efficient:       efficient?,
    wasteful:        wasteful?,
    burned_at:       @burned_at
  }
end

#wasteful?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/legion/extensions/agentic/homeostasis/fossil_fuel/helpers/combustion.rb', line 27

def wasteful?
  @energy_released < (@fuel_amount * 0.3)
end