Coder Social home page Coder Social logo

taxes_test's Introduction

Tax Calculator

Tax calculator receives an input list of product with their prices and categories and outputs the receipt with taxes included.

Environment

  • OSx 10.9.5
  • rvm 1.25.33
  • ruby-2.0.0-p353

Instalation

# after cloning it
$ bundle install

Usage

$ ruby taxes.rb < INPUT1
$ ruby taxes.rb < INPUT2
$ ruby taxes.rb < INPUT3

Testing

# for running the specs
$ rspec
# or, with guard
$ guard

Description

The application reads lines of comma separated data. Each line contains the following:

Quantity, Name, Price, Categories
1, Book 1, 10, imported|book

Categories are pipe separated and optional you can use any combination of the following: book, food, medical, imported. If no category is specified, a default general good category will be assigned.

Taxes rules

All products, except food, book, medical, will have an 10% tax. On top of this, any imported product will have an additional %5 tax.

Round method

The rounding rules for sales tax are that for a tax rate of n%, a shelf price of p contains (np/100 rounded up to the nearest 0.05) amount of sales tax.

Input example

Quantity, Product, Price, Categories
1, imported bottle of perfume, 27.99, imported
1, bottle of perfume, 18.99
1, packet of headache pills, 9.75, medical
1, box of imported chocolates, 11.25, imported|food

Output example

1, imported bottle of perfume, 32.19
1, bottle of perfume, 20.89
1, packet of headache pills, 9.75
1, box of imported chocolates, 11.85

Sales Taxes: 6.70
Total: 74.68

Design

The taxes.rb file receives the input and create a new instace of App. The invokes the method App#process, passing the input as a parameter and printing the returned string.

The App#process method will create an instance of Cart and will add the products from the input. After this it creates a Tax Class instance (this might differ depending on each country laws), in our case is simply Tax and passes it as a parameter to the Cart#apply_taxes method.

The Cart#apply_taxes method will go through each cart item and will calculate the tax for each product with the method Tax#calculate_tax.

Any Tax Class should implement the method #calculate_tax(product)

TODO

  • Optional first line in the input; It's kind of useless for now.
  • If 2 products have the same name and price, it should update the existing one in the cart, not adding a new one

taxes_test's People

Contributors

lemattma 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.