pmark / shopabcd Goto Github PK
View Code? Open in Web Editor NEWRuby sample code for a basic command line POS and Sinatra shopping cart.
Ruby sample code for a basic command line POS and Sinatra shopping cart.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.