Class: Fuelator::Calc
- Inherits:
-
Object
- Object
- Fuelator::Calc
- Defined in:
- lib/fuelator/calc.rb
Overview
Calculate fuel for a flight
Example:
>> Fuelator.Calc.new(28801, [[:launch, 9.807], [:land, 1.62], [:launch, 1.62], [:land, 9.807]]).run
=> 51898
Constant Summary collapse
- FLIGHT_CONSTANTS =
{ launch: { theta: 0.042, bias: 33, }, land: { theta: 0.033, bias: 42, }, }
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mass, pairs) ⇒ Calc
constructor
A new instance of Calc.
- #run ⇒ Object
Constructor Details
#initialize(mass, pairs) ⇒ Calc
Returns a new instance of Calc.
27 28 29 |
# File 'lib/fuelator/calc.rb', line 27 def initialize(mass, pairs) @parameters = Parameters.new(mass, pairs) end |
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
10 11 12 |
# File 'lib/fuelator/calc.rb', line 10 def parameters @parameters end |
Class Method Details
.run(mass, pairs) ⇒ Object
23 24 25 |
# File 'lib/fuelator/calc.rb', line 23 def self.run(mass, pairs) new(mass, pairs).run end |
Instance Method Details
#run ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/fuelator/calc.rb', line 31 def run parameters.validate! full_mass = parameters.mass parameters.reversed.map do |val| full_mass += recursive_calculate(full_mass, val) end.last - parameters.mass end |