Skip to content

Carolis/ruby-tax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sales Tax Calculator

Installation

# Clone the repository
git clone git@github.com:Carolis/ruby-tax.git

cd ruby-tax

# Install ruby dependencies
bundle install

# Finally run it 
./bin/sales_tax

Usage

Expected input format

{quantity} {product name} at {price}

Cents are separated by a dot using US convention

Input example:

  • 1 book at 12.49
  • 2 imported boxes of chocolates at 11.25
  • 1 imported bottle of perfume at 27.99

Keywords config:

  • imported anywhere in name will mark the item as subject to import duty
  • category keywords (book, chocolate, pills, etc.) may be tax exempt if not imported

Running the program

Important

You may need to give the program some permissions first if an error like Permission denied appears in the terminal.

# To change program permissions
chmod +x bin/sales_tax

Interactive mode

./bin/sales_tax

after inserting yours items you can either type done, press Command+D (or Ctrl+Z depending on your OS) to finish the input insertion

1 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85
done

Alternative modes

  • Paste multiple items at once and press Ctrl+D (Unix/Mac) or Ctrl+Z (Windows):

  • Insert a txt file as input

./bin/sales_tax < input.txt

Tip

You can use the original challenge input examples located in the examples folder

  • Use it as a pipe command with arguments
echo "1 book at 12.49
1 music CD at 14.99
1 chocolate bar at 0.85" | ./bin/sales_tax

Tests

# run all tests
bundle exec rspec

# run with coverage
bundle exec rspec --format documentation

# run specific test
bundle exec rspec spec/models/money_spec.rb

Custom exempt category config

Tax exempt categories are configured in config/categories.yml:

exempt_categories:
  book:
    keywords:
      - book
      - books
  food:
    keywords:
      - chocolate
      - chocolates
      - candy
  medical:
    keywords:
      - pill
      - pills
      - tablet
      - tablets

About

Ruby sales tax algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages