This Ruby application simulates a shopping basket, designed to manage purchases and calculate sales taxes according to specific rules. It elegantly handles tax calculations for both exempt and non-exempt items, including imported goods, ensuring accurate billing and receipt generation.
- Item Management: Add items with quantity, name, and price.
- Tax Calculation: Automatically calculates sales tax for items, distinguishing between exempt, non-exempt, and imported products.
- Receipt Generation: Produces a detailed receipt that includes each item's final price (tax inclusive) and the total cost.
- Tax Rounding: Rounds sales tax to the nearest 0.05 for precise accounting.
- Formatted Output: Ensures all numbers are presented with two decimal places for readability.
No installation is necessary for running this program directly. However, ensure Ruby is installed on your system. This program was developed and tested with Ruby 3.0.0, but it should be compatible with most recent Ruby versions.
The ShoppingBasket
class is at the core of this application. You can instantiate this class and use its methods to simulate a shopping experience.
Here's a quick start guide:
require_relative '../lib/shopping_basket'
# Initialize a new Shopping Basket
basket = ShoppingBasket.new
# Add items to the basket
basket.add_item(1, 'imported bottle of perfume', 27.99)
basket.add_item(1, 'bottle of perfume', 18.99)
basket.add_item(1, 'packet of headache pills', 9.75)
basket.add_item(1, 'imported box of chocolates', 11.25)
# Generate and print the receipt
basket.generate_receipt
Comprehensive RSpec tests are included to verify functionality across different scenarios, from tax calculations to receipt generation.
To run the tests, ensure you have RSpec installed. If not, you can install it with:
gem install rspec
Then Clone this repository to your local machine:
git clone https://github.com/lautarob/receipt_creator.git
Change to the project directory:
cd receipt_creator
Run the tests using the following command:
rspec
This will run all spec files located in the spec directory, providing a detailed report of each test case.