Class: EmptyInventoryChecker
- Inherits:
-
Object
- Object
- EmptyInventoryChecker
- Includes:
- DefaultErrorContainer
- Defined in:
- app/my_lib/empty_inventory_checker.rb
Overview
Check whether restaurant has empty inventory
Instance Method Summary collapse
-
#initialize(restaurant) ⇒ EmptyInventoryChecker
constructor
A new instance of EmptyInventoryChecker.
- #valid? ⇒ Boolean
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Constructor Details
#initialize(restaurant) ⇒ EmptyInventoryChecker
Returns a new instance of EmptyInventoryChecker.
8 9 10 11 12 13 |
# File 'app/my_lib/empty_inventory_checker.rb', line 8 def initialize(restaurant) @restaurant = restaurant @restaurant_info = restaurant.restaurant_info || restaurant.build_restaurant_info(has_dine_in_inventory: false, has_delivery_inventory: false) end |
Instance Method Details
#valid? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/my_lib/empty_inventory_checker.rb', line 15 def valid? if restaurant.is_dine_in? && restaurant.is_take_away? && restaurant_info.has_dine_in_inventory? && restaurant_info.has_delivery_inventory? return true elsif (restaurant.is_dine_in? && restaurant.is_take_away?) && (!restaurant_info.has_dine_in_inventory? && !restaurant_info.has_delivery_inventory?) errors.add(:base, 'Missing Dine In & Delivery Inventory') elsif (restaurant.is_dine_in? && !restaurant_info.has_dine_in_inventory?) || (restaurant.is_dine_in? && restaurant.is_take_away? && !restaurant_info.has_dine_in_inventory? && restaurant_info.has_delivery_inventory?) errors.add(:base, 'Missing Dine In Inventory') elsif (restaurant.is_take_away? && !restaurant_info.has_delivery_inventory?) || (restaurant.is_dine_in? && restaurant.is_take_away? && restaurant_info.has_dine_in_inventory? && !restaurant_info.has_delivery_inventory?) errors.add(:base, 'Missing Delivery Inventory') elsif restaurant.is_dine_in? && restaurant_info.has_dine_in_inventory? return true elsif restaurant.is_take_away? && restaurant_info.has_delivery_inventory? return true else errors.add(:base, 'Unknown Inventory Status') end errors.blank? end |