class SpaceshipMissionSimulator::SimulateEvent

Public Instance Methods

call() click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 21
def call
  context.event = build_event
  context.event.planet = identify_planet
  context.event.fuel_weight = calc_fuel
end

Private Instance Methods

build_event() click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 29
def build_event
  Event.new state: context.raw_data.first.to_sym,
            reserved_fuel_weight: context.reserved_fuel_weight
end
calc_fuel(mass = total_weight) click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 34
def calc_fuel(mass = total_weight)
  fuel = calc_fuel_by_event_formula mass, context.event.planet.gravity

  return 0 unless fuel.positive?

  calc_fuel(fuel) + fuel
end
calc_fuel_by_event_formula(mass, gravity) click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 42
def calc_fuel_by_event_formula(mass, gravity)
  if context.event.state == :land
    (mass * gravity * 0.033 - 42).to_i
  elsif context.event.state == :launch
    (mass * gravity * 0.042 - 33).to_i
  end
end
identify_planet() click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 50
def identify_planet
  IdentifyPlanet.call!(gravity: context.raw_data.last).planet
end
total_weight() click to toggle source
# File lib/spaceship_mission_simulator/interactors/simulate_event.rb, line 54
def total_weight
  context.initial_weight + context.reserved_fuel_weight
end