Giter Site home page Giter Site logo

checkout_gdp's Introduction

GDP Coding Exercise

All default products and rules are already created.

I built a Command Line Interface, run the cli.rb file and remember to install the terminal-table gem. You can find the next options at the CLI:

  1. Inventory: Get all the products from the store.
  2. Find product: Find a product given a specific code.
  3. Create product: Create a new product for the store.
  4. Scan product: Add a new item to checkout process.
  5. Total: Get the total value for checkout process after applying all the rules.
  6. Exit: Finish the program.

After add all products you want, enter 5 to calculate the total price and then enter the client name.

Premium clients (that has special pricing rules) are listed below:

  1. Unilever
  2. Nike
  3. Apple
  4. Ford

To add new rules, just edit the default_rules.json file. There are two types of rule:

  1. TwoForOneRule: this rules is used to apply the "Buy n and pay n-1" type of rule. E.g. Buy 4 and pay for 3. The strucure of this type of rule is shown below:
{
  "type"          : "twoforone", // type of rule
  "client"        : "UNILEVER",  // client that the rule must be applied
  "product"       : "classic",   // product that the rule affects
  "eligible_qtty" : "3"          // minimum quantity to apply the rule
},
  1. DiscountRule: this rules is used to apply new price to the products. E.g. Buy 4 product A (that costs $200 and pay $150 on each one. The strucure of this type of rule is shown below:
{
  "type"          : "discount",  // type of rule
  "client"        : "UNILEVER",  // client that the rule must be applied
  "product"       : "classic",   // product that the rule affects
  "eligible_qtty" : "0",         // minimum quantity to apply the rule. Use 0 (zero) to apply new price to every product on list
  "new_price"     : "309.99"     // new price to be used
},

Test

To run the test, just use the command ruby path_to_test_file.rb. The checkout_test.rb run all examples describe on the exercise.

checkout_gdp's People

Watchers

James Cloos avatar Weslley Almeida 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.