$ git clone git@github.com:misteral/checkout.git
$ bundle install
require 'checkout'
co = Checkout.new([Rules::BulkTshirt, Rules::BuyTwoGetOne])
co.scan("VOUCHER")
co.scan("VOUCHER")
co.scan("TSHIRT")
price = co.total
$ bundle exec rake console
$ bundle exec rspec .
Checkout class for calculating totals with promotion rules. Default load allowable products from './config/products.json'.
params:
- Array of Rules instance methods:
- scan(code) - add product to items and return product;
- total - return total amount with adjustments;
- default_rules - return default rules;
- product - returns allowable products;
- products= - replace current allowable products;
- items - current items(products) in Checkout.
Base class for checkout rules.
params:
- Array of Product as items in Checkout instance methods:
- eligible? - returns true if calculation can be implemented for this items;
- calculation - returns amount of discount for items;
- adjustment - return calculation if eligible.
'Buy 3 or more TSHIRT items, the price per unit should be 19.00' rule.
'Buy two of the same product, get one free' rule.
Main product class.
params:
- hash of data, example:
Product.new('name' => 'name', 'code' => 'code', 'price' => 34)
methods:
- load_products(file) - load products from json file