Class: TimeEstimationService
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- TimeEstimationService
- Defined in:
- app/services/time_estimation_service.rb
Overview
Service class that estimates the time required to deliver an order from a restaurant to a destination.
Instance Attribute Summary
Attributes inherited from ApplicationService
Instance Method Summary collapse
-
#initialize(order_type, restaurant:, destination:) ⇒ TimeEstimationService
constructor
Initializes a new TimeEstimationService object.
-
#result ⇒ Hash
Calculates the time required to deliver the order from the restaurant to the destination.
-
#set_cooking_estimation(cooking_estimation) ⇒ Object
Sets the estimated time required to cook the order.
Methods inherited from ApplicationService
Constructor Details
#initialize(order_type, restaurant:, destination:) ⇒ TimeEstimationService
Initializes a new TimeEstimationService object.
9 10 11 12 13 14 |
# File 'app/services/time_estimation_service.rb', line 9 def initialize(order_type, restaurant:, destination:) @destination = destination @order_type = order_type.to_sym @restaurant = restaurant @cooking_estimation = 0 end |
Instance Method Details
#result ⇒ Hash
Calculates the time required to deliver the order from the restaurant to the destination.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/services/time_estimation_service.rb', line 27 def result return non_delivery_result unless @order_type == :delivery calculator = DeliveryChannel::DistanceCalculator.new calculator_result = calculator.find_distance_to_restaurant(@destination, @restaurant) if calculator_result[:success] { success: calculator_result[:success], data: { time_estimation: @cooking_estimation + calculator_result[:duration].to_i, }, message: '', } else { success: false, data: {}, message: calculator_result[:message], } end end |
#set_cooking_estimation(cooking_estimation) ⇒ Object
Sets the estimated time required to cook the order.
19 20 21 |
# File 'app/services/time_estimation_service.rb', line 19 def set_cooking_estimation(cooking_estimation) @cooking_estimation = cooking_estimation end |