Giter Site home page Giter Site logo

shopabcd's Introduction

Shop ABCD 
By P. Mark Anderson

This code sample demonstrates a basic point-of-sale scanning API that accepts an arbitrary ordering of products (similar to what would happen when actually at a checkout line) and returns the correct total price for an entire shopping cart based on the per unit prices or the volume prices as applicable.

This implementation is written in Ruby and consists of four classes and a utility module. There are two ways to test this code as an API.

1) Run the command line test program.

    $ ruby cli/shop_abcd.rb


2) Copy and paste the code in run_online/shop_abcd_combined.rb into this online Ruby editor.

    http://www.compileonline.com/execute_ruby_online.php


BONUS

On reading the instructions again I noticed that they clearly state not to spend time on a UI. I certainly want to follow direction, but after completing the command line implementation I knew that making this code a Sinatra app hosted on AppFog with a Redis backend was a fairly minor task, so here's an additional way to test my work.

    http://shop.martianrover.com/


Below is a sample execution of the POS terminal test program being run from the command line. Thanks for your time!
Mark



$ ruby cli/shop_abcd.rb


[SHOP] Welcome to Shop ABCD
[SHOP] Initializing catalog

[CATALOG] New product: A $1.25
[CATALOG] New product: B $4.25
[CATALOG] New product: C $1.00
[CATALOG] New product: D $0.75
[CATALOG] New discount: 3 product A for $3.00
[CATALOG] New discount: 6 product C for $5.00


- - - - - - - - - - - - - - - -
[SHOP] Executing order 1: ABCDABA should be $13.25

[ORDER] Added product: A
[POS] TOTAL:  $1.25

[ORDER] Added product: B
[POS] TOTAL:  $5.50

[ORDER] Added product: C
[POS] TOTAL:  $6.50

[ORDER] Added product: D
[POS] TOTAL:  $7.25

[ORDER] Added product: A
[POS] TOTAL:  $8.50

[ORDER] Added product: B
[POS] TOTAL:  $12.75

[ORDER] Added product: A
[POS] SUBTOTAL:  $14.00
[POS] DISCOUNT: -$0.75
[POS] TOTAL:  $13.25



- - - - - - - - - - - - - - - -
[SHOP] Executing order 2: CCCCCCC should be $6.00

[ORDER] Added product: C
[POS] TOTAL:  $1.00

[ORDER] Added product: C
[POS] TOTAL:  $2.00

[ORDER] Added product: C
[POS] TOTAL:  $3.00

[ORDER] Added product: C
[POS] TOTAL:  $4.00

[ORDER] Added product: C
[POS] TOTAL:  $5.00

[ORDER] Added product: C
[POS] SUBTOTAL:  $6.00
[POS] DISCOUNT: -$1.00
[POS] TOTAL:  $5.00

[ORDER] Added product: C
[POS] SUBTOTAL:  $7.00
[POS] DISCOUNT: -$1.00
[POS] TOTAL:  $6.00



- - - - - - - - - - - - - - - -
[SHOP] Executing order 3: ABCD should be $7.25

[ORDER] Added product: A
[POS] TOTAL:  $1.25

[ORDER] Added product: B
[POS] TOTAL:  $5.50

[ORDER] Added product: C
[POS] TOTAL:  $6.50

[ORDER] Added product: D
[POS] TOTAL:  $7.25


shopabcd's People

Contributors

pmark avatar

Watchers

 avatar Gábor Nagymajtényi 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.