module TaxCalculator::Federal

Constants

BRACKETS

2021

Public Class Methods

taxes_for(income) click to toggle source
# File lib/tax_calculator/federal.rb, line 18
def self.taxes_for(income)
  previous_amount = 0
  taxes_owed = 0

  BRACKETS[:married].each_pair do |bracket, amount|
    if amount == :remaining
      taxes_owed = taxes_owed + ((income - previous_amount) * (bracket / 100))
      break
    end

    if income < amount
      taxes_owed = taxes_owed + ((income - previous_amount) * (bracket / 100))
      break
    end

    taxes_owed = taxes_owed + ((amount - previous_amount) * (bracket / 100))
    previous_amount = amount
    break if amount == income
  end

  taxes_owed.round(2)
end