Class: HhAddOn::ReservationAddOns::SelectedAddOnsBuilder
- Inherits:
-
Object
- Object
- HhAddOn::ReservationAddOns::SelectedAddOnsBuilder
- Defined in:
- app/my_lib/hh_add_on/reservation_add_ons/selected_add_ons_builder.rb
Overview
HhAddOn::ReservationAddOns::SelectedAddOnsBuilder is responsible for building a list of selected add_ons based on the provided add_ons and pricing rules.
This builder class calculates base prices, applies mix-and-match quantity rules, handles pricing for adults and kids, and optionally applies promotional pricing
Instance Method Summary collapse
-
#build ⇒ Array<Hash>
Build the selected add_ons and calculate prices for adults and kids.
-
#initialize(add_ons:, restaurant_add_on_id:, adult:, kids:, price_cents:) ⇒ SelectedAddOnsBuilder
constructor
A new instance of SelectedAddOnsBuilder.
Constructor Details
#initialize(add_ons:, restaurant_add_on_id:, adult:, kids:, price_cents:) ⇒ SelectedAddOnsBuilder
Returns a new instance of SelectedAddOnsBuilder.
32 33 34 35 36 37 38 39 40 |
# File 'app/my_lib/hh_add_on/reservation_add_ons/selected_add_ons_builder.rb', line 32 def initialize(add_ons:, restaurant_add_on_id:, adult:, kids:, price_cents:) @add_ons = add_ons @restaurant_add_on_id = restaurant_add_on_id @adult = to_integer(adult) @kids = to_integer(kids) @price_cents = price_cents @price_finder = HhPackage::ReservationPackages::PriceFinder.new @selected_kids_price_add_on_id = nil end |
Instance Method Details
#build ⇒ Array<Hash>
Build the selected add_ons and calculate prices for adults and kids.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/my_lib/hh_add_on/reservation_add_ons/selected_add_ons_builder.rb', line 45 def build selected_add_on = find_selected_add_on return [] if selected_add_on.blank? add_on = selected_add_on[:add_on] binding base_price = add_on.pricing.price_cents selected_qty = selected_add_on[:quantity] kids_price_data = find_kids_price_if_applicable(add_on) adult_price = calculate_adult_price(base_price, selected_qty) kids_price = calculate_kids_price(kids_price_data[:price]).cents adult_price = ensure_valid_adult_price(adult_price, add_on) build_selected_add_ons_response(add_on, selected_qty, kids_price, kids_price_data, base_price, adult_price) end |