Class: InvCheckerFactory
- Inherits:
-
Object
- Object
- InvCheckerFactory
- 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
-
#restaurant_id ⇒ Object
readonly
Returns the value of attribute restaurant_id.
-
#time_zone ⇒ Object
readonly
Returns the value of attribute time_zone.
Class Method Summary collapse
-
.flush_db ⇒ void
Flushes the Redis database used for inventory checking.
Instance Method Summary collapse
-
#available_packages(date:, start_time:, adult:, kids:) ⇒ Array<String>
Gets available packages for the given parameters.
-
#bookable_without_adult?(date:, start_time:) ⇒ Boolean
Checks if inventory is bookable without adult count for the given parameters.
-
#create_inv_checker_service ⇒ Inventory::InvCheckerBaseService
Creates an instance of the appropriate inventory checker service based on restaurant characteristics.
-
#initialize(restaurant_id, time_zone) ⇒ InvCheckerFactory
constructor
Initializes a new InvCheckerFactory instance.
-
#inv_checker_service_class ⇒ Class
Determines the class of the inventory checker service based on restaurant characteristics.
-
#inventory_bookable?(date, start_time, adult, kids) ⇒ Boolean
Checks if inventory is bookable for the given parameters.
-
#package_bookable?(date:, start_time:, adult:, kids:, slug:) ⇒ Boolean
Checks if a package is bookable for the given parameters.
Constructor Details
#initialize(restaurant_id, time_zone) ⇒ InvCheckerFactory
Initializes a new InvCheckerFactory instance.
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_id ⇒ Object (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_zone ⇒ Object (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_db ⇒ void
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.
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.
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_service ⇒ Inventory::InvCheckerBaseService
Creates an instance of the appropriate inventory checker service based on restaurant characteristics.
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_class ⇒ Class
Determines the class of the inventory checker service based on restaurant characteristics.
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::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.
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.
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 |