Class: AddOnServices::Processor

Inherits:
Object
  • Object
show all
Defined in:
app/services/add_on_services/processor.rb

Overview

The Processor class is responsible for processing add_ons and validating mix-and-match options for a given restaurant.

Examples:

Usage

processor = AddOnServices::Processor.new(params_add_on_bought, restaurant)
add_on_bought, is_valid = processor.process_add_ons

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params_add_on_bought, restaurant = nil, adult = nil) ⇒ Processor

Initializes a new Processor object to handle the add-on processing.

Parameters:

  • params_add_on_bought (Hash)

    The parameters for the bought add_ons.

  • restaurant (Restaurant, nil) (defaults to: nil)

    The associated restaurant, defaults to nil.



26
27
28
29
30
# File 'app/services/add_on_services/processor.rb', line 26

def initialize(params_add_on_bought, restaurant = nil, adult = nil)
  @add_on_data = params_add_on_bought[:add_ons] || params_add_on_bought['add_on_bought'] || params_add_on_bought[:add_on_bought] || []
  @restaurant = restaurant
  @adult = adult.to_i
end

Instance Attribute Details

#add_on_boughtHash (readonly)

Returns the parameters of the add_ons that were bought.

Returns:

  • (Hash)

    the parameters of the add_ons that were bought.



12
# File 'app/services/add_on_services/processor.rb', line 12

attr_reader :add_on_data

#add_on_dataObject (readonly)

Returns the value of attribute add_on_data.



12
13
14
# File 'app/services/add_on_services/processor.rb', line 12

def add_on_data
  @add_on_data
end

#adultObject (readonly)

Returns the value of attribute adult.



20
21
22
# File 'app/services/add_on_services/processor.rb', line 20

def adult
  @adult
end

#restaurantObject (readonly)

Returns the value of attribute restaurant.



16
17
18
# File 'app/services/add_on_services/processor.rb', line 16

def restaurant
  @restaurant
end

Instance Method Details

#process_add_onsArray

Processes the bought add_ons and checks if they are valid for mix-and-match.

Examples:

Process add_ons

processor = AddOnServices::Processor.new(params_add_on_bought, restaurant)
add_on_bought, is_valid = processor.process_add_ons

Returns:

  • (Array)

    Returns an array containing the processed add_ons and a boolean indicating if mix-and-match is valid.



39
40
41
42
43
# File 'app/services/add_on_services/processor.rb', line 39

def process_add_ons
  add_on_data.map do |param|
    process_single_add_on(param)
  end
end