Project

tax_girl

0.0
No commit activity in last 3 years
No release in over 3 years
TaxGirl is a simple tool that helps keeping calculation logic explicit using a ruby DSL.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
>= 3.1.0, ~> 3.1
 Project Readme

tax_girl

Build Status Code Climate Test Coverage

Introduction

TaxGirl is a simple tool that help's keeping calculation logic explicit using a pretty ruby DSL. It also avoids the hard work of seaching for layers and layers of calculation methods.

Composing price

Increase block

Block where you define which methods will be triggered to compose the main price amount.

Params

currency and percentage - Accepts a method or list of methods symbols that will be triggered on the moment you call the method passed as param to taxgirl (price on the example below).

Obs: percentage methods amounts will be applied on typed order.

class Product
  taxgirl :price do
    increase do
      currency   :provider_price, :convenience_fee
      percentage :commission_fee, :another_fee
    end
  end
  
  def provider_price
    105.5
  end

  def convenience_fee
    5.0
  end

  def commission_fee
    # It means 10% to tax girl
    10.0
  end

  def another_fee
    # It means 5.5% to tax girl
    5.5
  end
end

product = Product.new
product.price

=> 128.23525

Obs: price will be calculated every time it's called.

Discount block

Block where you define which methods will be triggered to discount the main price amount calculated on increase block.

class Product
  taxgirl :price do
    increase do
      currency   :provider_price, :convenience_fee
      percentage :commission_fee, :another_fee
    end

    discount do
      currency   :special_coupon_discount
      percentage :black_friday_discount
    end
  end
  
  def provider_price
    105.5
  end

  def convenience_fee
    5.0
  end

  def commission_fee
    # It means 10% to tax girl
    10.0
  end

  def another_fee
    # It means 5.5% to tax girl
    5.5
  end

  def special_coupon_discount
    20.0
  end

  def black_friday_discount
    # It means 15% to tax girl
    15.0
  end
end

product = Product.new
product.price

=> 91.99996250000001

Contributing

  • Create an issue
  • Fork the project
  • Send a pull request
  • Have fun! :)