Class: HhPackage::DynamicPricingTitleGenerator

Inherits:
Object
  • Object
show all
Defined in:
app/my_lib/hh_package/dynamic_pricing_title_generator.rb

Overview

This service generates a dynamic pricing title based on a given package and criteria. It determines the appropriate pricing title by evaluating different pricing models such as “Come More Pay Less”, “By Party Size”, or “By Day Pricing”.

Example Usage:

generator = HhPackage::DynamicPricingTitleGenerator.new(
  pkg: my_package,
  date: Date.today,
  adult: 2,
  kids: 1,
  price_cents: 10000,
  use_dynamic_pricing: true
)
title = generator.call
puts title

Instance Method Summary collapse

Constructor Details

#initialize(pkg:, date:, adult:, kids:, price_cents:, use_dynamic_pricing: true) ⇒ DynamicPricingTitleGenerator

Initializes the generator with the required attributes

Parameters:

  • pkg (Object)

    The package object containing pricing data

  • date (Date)

    The selected date for the reservation

  • adult (Integer)

    Number of adults in the reservation

  • kids (Integer)

    Number of kids in the reservation

  • price_cents (Integer)

    The price in cents for the package

  • use_dynamic_pricing (Boolean) (defaults to: true)

    Whether to use dynamic pricing (default: true)



28
29
30
31
32
33
34
35
36
# File 'app/my_lib/hh_package/dynamic_pricing_title_generator.rb', line 28

def initialize(pkg:, date:, adult:, kids:, price_cents:, use_dynamic_pricing: true)
  @pkg = pkg
  @date = date
  @adult = adult
  @kids = kids
  @price_cents = price_cents
  @use_dynamic_pricing = use_dynamic_pricing
  @price_finder = HhPackage::ReservationPackages::PriceFinder.new(use_dynamic_pricing: use_dynamic_pricing)
end

Instance Method Details

#callString?

Determines the dynamic pricing title based on the package and criteria.

Returns empty string when use_dynamic_pricing is false

Returns:

  • (String, nil)

    The dynamic pricing title, or nil if no pricing applies



42
43
44
45
46
47
# File 'app/my_lib/hh_package/dynamic_pricing_title_generator.rb', line 42

def call
  return come_more_pay_less_title if @price_finder.valid_come_more_pay_less?(@pkg, @date)
  return by_party_size_title if by_party_size_pricing?

  day_pricing_title
end