Module: TaxCalculator::Federal

Defined in:
lib/tax_calculator/federal.rb

Constant Summary collapse

BRACKETS =

2021

{
  :married => {
    10.0 => 20_550.00,
    12.0 => 83_550.00,
    22.0 => 178_150.00,
    24.0 => 340_100.00,
    32.0 => 431_900.00,
    35.0 => 647_850.00,
    37.0 => :remaining
  }.freeze
}.freeze

Class Method Summary collapse

Class Method Details

.taxes_for(income) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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