GithubHelp home page GithubHelp logo

checkout's Introduction

CHECKOUT

This Ruby code implements a checkout system with promotion rules on products.

Here is a sample of some of the products available:

Product code  | Name                   | Price
----------------------------------------------------------
001           | Lavender heart         | £9.25
002           | Personalised cufflinks | £45.00
003           | Kids T-shirt           | £19.95

These are the discount rules to apply:

If you spend over £60, then you get 10% of your purchase.
If you buy 2 or more lavender hearts then the price drops to £8.50.

Implementation

The implementation is based on several Ruby classes:

  • Promotion superclass that implements common behaviour to specialized discount classes.

  • LavenderPair promotion subclass implements the computation and discount applicable to each pair of Lavander products.

  • Over60 promotion subclass implements the computation and discount applicable totals over 60 pounds.

  • Item class implements a basic item concept with name and price.

  • Checkout class implements the checkout process. Scan of items and computation of total price with promotions applied.

Installation

Clone the code from Checkout

Install Ruby 2.6.4

If Ruby runtime is not installed in your machine, please install it first. Some popular ruby version managers might be helpful: rbenv, rvm

Install dependencies

You will need Bundler gem to install Ruby dependencies. In the root directory where you the code is installed check it is installed and accessible typing:

bundle install

Run the code

irb
require "./co" 
item1 = Item.new(name: "Lavender heart", price: 9.25)
item2 = Item.new(name: "Personalised cufflinks", price: 45.00)
item3 = Item.new(name: "Kids T-shirt", price: 19.95)

Now you try the following checkout example:

co = Checkout.new([LavenderPair, Over60])
co.scan(item1)
co.scan(item2)
co.scan(item3)
co.total

You should get 66.78

Other examples:

Basket: 001,003,001
Total price expected: £36.95

Basket: 001,002,001,003
Total price expected: £73.76

Run the test suite

In the root folder where you installed the code, type:

rspec

You can check test coverage if you type this after running rspec:

open coverage/index.html

checkout's People

Contributors

ltello avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.