Class: PackageServices::Processor

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

Overview

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

Examples:

Usage

processor = PackageServices::Processor.new(params_package_bought, restaurant)
package_bought, is_valid = processor.process_packages

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Processor object to handle the package processing.

Parameters:

  • params_package_bought (Hash) —

    The parameters for the bought packages.

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

    The associated restaurant, defaults to nil.



30
31
32
33
34
35
# File 'app/services/package_services/processor.rb', line 30

def initialize(params_package_bought, restaurant = nil, adult = nil)
  @package_data = params_package_bought[:packages] || params_package_bought['package_bought'] || params_package_bought[:package_bought] || []
  @restaurant = restaurant
  @is_valid_mix_n_match = true
  @adult = adult.to_i
end

Instance Attribute Details

#adult ⇒ Object (readonly)

Returns the value of attribute adult.



24
25
26
# File 'app/services/package_services/processor.rb', line 24

def adult
  @adult
end

#is_valid_mix_n_match ⇒ Object (readonly)

Returns the value of attribute is_valid_mix_n_match.



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

def is_valid_mix_n_match
  @is_valid_mix_n_match
end

#package_bought ⇒ Hash (readonly)

Returns the parameters of the packages that were bought.

Returns:

  • (Hash) —

    the parameters of the packages that were bought.



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

attr_reader :package_data

#package_data ⇒ Object (readonly)

Returns the value of attribute package_data.



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

def package_data
  @package_data
end

#restaurant ⇒ Object (readonly)

Returns the value of attribute restaurant.



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

def restaurant
  @restaurant
end

Instance Method Details

#process_packages ⇒ Array

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

Examples:

Process packages

processor = PackageServices::Processor.new(params_package_bought, restaurant)
package_bought, is_valid = processor.process_packages

Returns:

  • (Array) —

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



44
45
46
47
48
49
# File 'app/services/package_services/processor.rb', line 44

def process_packages
  package_bought = package_data.map do |param|
    process_single_package(param)
  end
  [package_bought, is_valid_mix_n_match]
end