Class: DynamicPricingsFlipper

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

Overview

When the given data is not ready for dynamic pricing feature this class will make the dynamic price to act like the old pricing feature

Instance Method Summary collapse

Constructor Details

#initialize(time_zone = nil) ⇒ DynamicPricingsFlipper

Returns a new instance of DynamicPricingsFlipper.



4
5
6
# File 'app/my_lib/dynamic_pricings_flipper.rb', line 4

def initialize(time_zone = nil)
  @time_zone = time_zone if time_zone.present?
end

Instance Method Details

#filter_by_package(prices, package, support_dynamic_pricing_feature) ⇒ Object

this method will tranform per_person_and_by_day_price pricing to be per_person_and_normal_price if the pricing is not per_person_and_by_day_price, then it will return the prices as is this is a temporary solution to make the dynamic pricing to be compatible with the old pricing for any client who haven't implemented dynamic pricing yet

Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/my_lib/dynamic_pricings_flipper.rb', line 15

def filter_by_package(prices, package, support_dynamic_pricing_feature)
  # filter prices that are not expired
  today = if @time_zone.present?
            Time.now_in_tz(@time_zone).to_date
          else
            Date.current_date
          end

  prices = prices.where('end_date IS NULL OR end_date >= ?', today)

  return prices if support_dynamic_pricing_feature
  return prices if !need_to_tranform?(package)

  find_most_expensive_price(prices)
end