This Ruby project implements a cashier system that supports various pricing rules such as Buy One Get One Free, Discounts, and Two-Thirds off.
-
Clone the repository:
git clone git@github.com:arnaub/supermarket.git cd supermarket -
Install dependencies using Bundler:
bundle install
Follow the steps below to use the Cashier system in an interactive Ruby session:
-
Start an interactive Ruby session with Sorbet runtime:
bundle exec irb -r sorbet-runtime -
Require the necessary files:
require_relative "./cashier/items" require_relative "./cashier/checkout"
-
Initialize the rules and the checkout system:
rules = Cashier::Rules::Manager.new.list checkout = Cashier::Checkout.new(rules)
-
Find an item and scan it:
item = Cashier::Items.find('CF1') checkout.scan(item)
-
View scanned items:
checkout.items
-
Calculate the total:
checkout.total
Here's a full example of using the Cashier system:
# Start IRB session with Sorbet runtime
bundle exec irb -r sorbet-runtime
# Require necessary files
require_relative "./cashier/items"
require_relative "./cashier/checkout"
# Initialize rules and checkout system
rules = Cashier::Rules::Manager.new.list
checkout = Cashier::Checkout.new(rules)
# Find and scan an item
item = Cashier::Items.find('CF1')
checkout.scan(item)
# View scanned items
checkout.items
# Calculate the total
checkout.total