aboutsummaryrefslogtreecommitdiffstats
path: root/app/services/route_way_cost_calculator.rb
blob: ca47a67725a335514c7c343fc38b4d9f5447166a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class RouteWayCostCalculator
  def initialize(route)
    @route = route
  end

  def calculate!
    way_costs = StopAreasToWayCostsConverter.new(@route.stop_areas).convert
    way_costs = TomTom.matrix(way_costs)
    way_costs = WayCostCollectionJSONSerializer.dump(way_costs)
    @route.update(costs: way_costs)
  rescue TomTom::Errors::MatrixRemoteError => e
    Rails.logger.error "TomTom::Matrix server error: #{e}"
  end
end