Class: PackageServices::DynamicPricings

Inherits:
Object
  • Object
show all
Defined in:
app/services/package_services/dynamic_pricings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, restaurant) ⇒ DynamicPricings

Initializes the service with parameters and restaurant.

Parameters:

  • params (Hash)

    the parameters for the request, including filters and calculation inputs.

  • restaurant (Restaurant)

    the restaurant to which packages belong.



28
29
30
31
32
33
34
# File 'app/services/package_services/dynamic_pricings.rb', line 28

def initialize(params, restaurant)
  @params = params
  @restaurant = restaurant
  @message = ''
  @success = false
  @data = []
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'app/services/package_services/dynamic_pricings.rb', line 22

def data
  @data
end

#messageObject (readonly)

Returns the value of attribute message.



22
23
24
# File 'app/services/package_services/dynamic_pricings.rb', line 22

def message
  @message
end

#paramsObject (readonly)

Returns the value of attribute params.



22
23
24
# File 'app/services/package_services/dynamic_pricings.rb', line 22

def params
  @params
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



22
23
24
# File 'app/services/package_services/dynamic_pricings.rb', line 22

def restaurant
  @restaurant
end

#successObject (readonly)

Returns the value of attribute success.



22
23
24
# File 'app/services/package_services/dynamic_pricings.rb', line 22

def success
  @success
end

Instance Method Details

#processvoid

This method returns an undefined value.

Processes the dynamic pricing calculation flow. Calls methods to filter packages, calculate pricing, and build the response result.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/services/package_services/dynamic_pricings.rb', line 40

def process
  filter_packages
  calculate_packages
  build_result
rescue ActiveRecord::RecordNotFound
  raise RecordNotFoundButOk
rescue InvalidPackageData => e
  @message = e.message
  @success = false
rescue Date::Error => e
  @message = e.message
  @success = false
rescue StandardError => e
  handle_error(e)
end