Class: InvCheckerFactory

Inherits:
Object
  • Object
show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/my_lib/inv_checker_factory.rb

Overview

Factory class for creating inventory checker services based on restaurant characteristics. Example usage:

inv_checker_factory = InvCheckerFactory.new(restaurant.id, restaurant.time_zone)
inv_checker = inv_checker_factory.create_inv_checker_service
inv_checker.bookable?(date, start_time, adult, kids)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurant_id, time_zone) ⇒ InvCheckerFactory

Initializes a new InvCheckerFactory instance.

Parameters:

  • restaurant_id (Integer)

    The ID of the restaurant.

  • time_zone (String)

    The time zone of the restaurant.



17
18
19
20
# File 'app/my_lib/inv_checker_factory.rb', line 17

def initialize(restaurant_id, time_zone)
  @restaurant_id = restaurant_id
  @time_zone = time_zone
end

Instance Attribute Details

#restaurant_idObject (readonly)

Returns the value of attribute restaurant_id.



11
12
13
# File 'app/my_lib/inv_checker_factory.rb', line 11

def restaurant_id
  @restaurant_id
end

#time_zoneObject (readonly)

Returns the value of attribute time_zone.



11
12
13
# File 'app/my_lib/inv_checker_factory.rb', line 11

def time_zone
  @time_zone
end

Class Method Details

.flush_dbvoid

This method returns an undefined value.

Flushes the Redis database used for inventory checking.

This method clears all data in the Redis database used for inventory checking. It is typically called when there are changes in admin settings that affect inventory checking.



35
36
37
38
39
# File 'app/my_lib/inv_checker_factory.rb', line 35

def self.flush_db
  $inv_redis.with do |redis|
    redis.flushdb
  end
end

Instance Method Details

#available_packages(date:, start_time:, adult:, kids:) ⇒ Array<String>

Gets available packages for the given parameters. This is a convenience method that creates the service and calls available_packages on it.

Parameters:

  • date (Date)

    The date of the booking.

  • start_time (String)

    The start time of the booking (e.g., '18:00').

  • adult (Integer)

    The number of adult guests.

  • kids (Integer)

    The number of children guests.

Returns:

  • (Array<String>)

    Array of available package slugs.



78
79
80
81
# File 'app/my_lib/inv_checker_factory.rb', line 78

def available_packages(date:, start_time:, adult:, kids:)
  inv_checker = create_inv_checker_service
  inv_checker.available_packages(date: date, start_time: start_time, adult: adult, kids: kids)
end

#bookable_without_adult?(date:, start_time:) ⇒ Boolean

Checks if inventory is bookable without adult count for the given parameters. This is a convenience method that creates the service and calls bookable_without_adult? on it.

Parameters:

  • date (Date)

    The date of the booking.

  • start_time (String)

    The start time of the booking (e.g., '18:00').

Returns:

  • (Boolean)

    True if booking is possible without adult specification, false otherwise.



90
91
92
93
# File 'app/my_lib/inv_checker_factory.rb', line 90

def bookable_without_adult?(date:, start_time:)
  inv_checker = create_inv_checker_service
  inv_checker.bookable_without_adult?(date: date, start_time: start_time)
end

#create_inv_checker_serviceInventory::InvCheckerBaseService

Creates an instance of the appropriate inventory checker service based on restaurant characteristics.

Returns:



25
26
27
# File 'app/my_lib/inv_checker_factory.rb', line 25

def create_inv_checker_service
  inv_checker_service_class.new(restaurant_id, time_zone)
end

#inv_checker_service_classClass

Determines the class of the inventory checker service based on restaurant characteristics.

Returns:

  • (Class)

    The class of the inventory checker service.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/my_lib/inv_checker_factory.rb', line 99

def inv_checker_service_class
  if restaurant.inventory_seven_rooms?
    Inventory::InvCheckerSevenRoomsService
  elsif restaurant.inventory_tablecheck?
    Inventory::InvCheckerTablecheckService
  elsif restaurant.inventory_weeloy?
    Inventory::InvCheckerWeeloyService
  elsif restaurant.inventory_bistrochat?
    Inventory::InvCheckerBistrochatService
  elsif restaurant.inventory_my_menu?
    Inventory::InvCheckerMyMenuService
  else
    Inventory::InvCheckerHungryHubService
  end
end

#inventory_bookable?(date, start_time, adult, kids) ⇒ Boolean

Checks if inventory is bookable for the given parameters. This is a convenience method that creates the service and calls bookable? on it.

Parameters:

  • date (Date)

    The date of the booking.

  • start_time (String)

    The start time of the booking (e.g., '18:00').

  • adult (Integer)

    The number of adult guests.

  • kids (Integer)

    The number of children guests.

Returns:

  • (Boolean)

    True if booking is possible, false otherwise.



49
50
51
52
# File 'app/my_lib/inv_checker_factory.rb', line 49

def inventory_bookable?(date, start_time, adult, kids)
  inv_checker = create_inv_checker_service
  inv_checker.bookable?(date: date, start_time: start_time, adult: adult, kids: kids)
end

#package_bookable?(date:, start_time:, adult:, kids:, slug:) ⇒ Boolean

Checks if a package is bookable for the given parameters. This is a convenience method that creates the service and calls package_bookable? on it.

Parameters:

  • date (Date)

    The date of the booking.

  • start_time (String)

    The start time of the booking (e.g., '18:00').

  • adult (Integer)

    The number of adult guests.

  • kids (Integer)

    The number of children guests.

  • slug (String)

    The package slug identifier.

Returns:

  • (Boolean)

    True if package booking is possible, false otherwise.



64
65
66
67
# File 'app/my_lib/inv_checker_factory.rb', line 64

def package_bookable?(date:, start_time:, adult:, kids:, slug:)
  inv_checker = create_inv_checker_service
  inv_checker.package_bookable?(date: date, start_time: start_time, adult: adult, kids: kids, slug: slug)
end