us_income_tax 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/data/hsa_max_contribution.json +12 -0
- data/lib/us_income_tax/bracket_loader.rb +1 -1
- data/lib/us_income_tax/calculation_result.rb +16 -2
- data/lib/us_income_tax/calculator.rb +2 -2
- data/lib/us_income_tax/dto/calculation_result_options.rb +13 -0
- data/lib/us_income_tax/dto/calculation_result_options_hsa.rb +13 -0
- data/lib/us_income_tax/hsa/calculation_result.rb +53 -0
- data/lib/us_income_tax/hsa/max_contribution_data_loader.rb +15 -0
- data/lib/us_income_tax/hsa/taxable_income_calculator.rb +11 -0
- data/lib/us_income_tax/version.rb +1 -1
- data/lib/us_income_tax.rb +9 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3639492ccdf61733ef512b0e68001617d05629d8f3f82ce8a7ef2c5304875881
|
4
|
+
data.tar.gz: df5653fa5fcbd73e46baf9a832a6330efe21b0c7e2f2ebbbe6064214a6cc6df8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d8df64eee361d8e176daedda7ca60a3bebb4439bdc2d3c06e7199539e108bbfad4fa0251b2f35a65047fb4e1213f91b71c614ffa008dc055e5c18d3f11c8b24
|
7
|
+
data.tar.gz: 0f49e9cfa8962b4a93acb5f536a4f3bb3b207a1a468267808bd06673fe96b360fa043c75eea172f4b8c64a01023deb4ee5a42a11e7a30a1f0af021260909edc1
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module USIncomeTax
|
2
2
|
class CalculationResult
|
3
|
-
attr_accessor :year, :gross_income, :type, :brackets, :total_tax, :net_income
|
3
|
+
attr_accessor :year, :gross_income, :taxable_income, :type, :brackets, :total_tax, :net_income, :options
|
4
4
|
|
5
|
-
def initialize(year, gross_income, type)
|
5
|
+
def initialize(year, gross_income, type, options)
|
6
6
|
@year = year
|
7
7
|
@gross_income = gross_income
|
8
|
+
@taxable_income = @gross_income # By default, taxable income is the same as the gross income
|
8
9
|
@type = type
|
9
10
|
|
10
11
|
loaded_static_brackets = ::USIncomeTax::BracketLoader.load
|
@@ -12,11 +13,16 @@ module USIncomeTax
|
|
12
13
|
@brackets = BracketLibrary.new(loaded_static_brackets).content
|
13
14
|
@total_tax = nil
|
14
15
|
@net_income = nil
|
16
|
+
|
17
|
+
return if options.nil?
|
18
|
+
|
19
|
+
@options = DTO::CalculationResultOptions.new(options)
|
15
20
|
end
|
16
21
|
|
17
22
|
def calculate
|
18
23
|
assign_income_to_tax_brackets
|
19
24
|
calculate_tax_brackets
|
25
|
+
calculate_taxable_income
|
20
26
|
calculate_total_tax
|
21
27
|
calculate_net_income
|
22
28
|
end
|
@@ -33,6 +39,14 @@ module USIncomeTax
|
|
33
39
|
end
|
34
40
|
|
35
41
|
# Must call assign_income_to_tax_brackets before usage
|
42
|
+
def calculate_taxable_income
|
43
|
+
return if @options.nil? || @options.hsa.nil?
|
44
|
+
|
45
|
+
hsa_calculation_result = Hsa::TaxableIncomeCalculator.calculate(@year, @gross_income, @options.hsa)
|
46
|
+
@taxable_income = hsa_calculation_result.taxable_income
|
47
|
+
end
|
48
|
+
|
49
|
+
# Must call calculate_taxable_income before usage
|
36
50
|
def calculate_tax_brackets
|
37
51
|
types_in_year = @brackets[@year.to_s]
|
38
52
|
brackets_in_type = types_in_year[@type.to_sym]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module USIncomeTax
|
2
2
|
class Calculator
|
3
|
-
def self.calculate(year, gross_income, type)
|
4
|
-
calculation_result = CalculationResult.new(year, gross_income, type)
|
3
|
+
def self.calculate(year, gross_income, type, options)
|
4
|
+
calculation_result = CalculationResult.new(year, gross_income, type, options)
|
5
5
|
calculation_result.calculate
|
6
6
|
calculation_result
|
7
7
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module USIncomeTax
|
2
|
+
module DTO
|
3
|
+
class CalculationResultOptionsHsa
|
4
|
+
attr_accessor :year, :hsa_contribution_amount, :hsa_type
|
5
|
+
|
6
|
+
def initialize(hsa_options)
|
7
|
+
@year = hsa_options[:year]
|
8
|
+
@hsa_contribution_amount = hsa_options[:hsa_contribution_amount]
|
9
|
+
@hsa_type = hsa_options[:hsa_type]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module USIncomeTax
|
2
|
+
module Hsa
|
3
|
+
class CalculationResult
|
4
|
+
attr_accessor :year, :gross_income, :taxable_income, :options, :max_contributions
|
5
|
+
|
6
|
+
def initialize(year, gross_income, hsa_options)
|
7
|
+
@year = year
|
8
|
+
@gross_income = gross_income
|
9
|
+
@taxable_income = 0
|
10
|
+
@options = hsa_options
|
11
|
+
@max_contributions = MaxContributionDataLoader.load
|
12
|
+
end
|
13
|
+
|
14
|
+
def calculate
|
15
|
+
validation_result = validate_inputs
|
16
|
+
nil unless validation_result[:valid]
|
17
|
+
|
18
|
+
@taxable_income = @gross_income - @options.hsa_contribution_amount
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate_inputs
|
22
|
+
year_contributions = @max_contributions[@year.to_s]
|
23
|
+
|
24
|
+
if @options.hsa_type == "self-only"
|
25
|
+
if @options.hsa_contribution_amount > year_contributions["self-only"]
|
26
|
+
{
|
27
|
+
valid: false,
|
28
|
+
message: "HSA contribution amount exceeds the maximum contribution amount for self-only HSA"
|
29
|
+
}
|
30
|
+
else
|
31
|
+
{
|
32
|
+
valid: true,
|
33
|
+
message: nil
|
34
|
+
}
|
35
|
+
end
|
36
|
+
elsif @options.hsa_type == "family"
|
37
|
+
if @options.hsa_contribution_amount > year_contributions["family"]
|
38
|
+
{
|
39
|
+
valid: false,
|
40
|
+
message: "HSA contribution amount exceeds the maximum contribution amount for family HSA"
|
41
|
+
}
|
42
|
+
else
|
43
|
+
{
|
44
|
+
valid: true,
|
45
|
+
message: nil
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# TODO: handle additional-catch-up
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module USIncomeTax
|
4
|
+
module Hsa
|
5
|
+
class MaxContributionDataLoader
|
6
|
+
FILE_PATH = "../../../data/hsa_max_contribution.json"
|
7
|
+
|
8
|
+
def self.load
|
9
|
+
json_file_path = File.expand_path(FILE_PATH, __dir__)
|
10
|
+
file = File.read(json_file_path)
|
11
|
+
JSON.parse(file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module USIncomeTax
|
2
|
+
module Hsa
|
3
|
+
class TaxableIncomeCalculator
|
4
|
+
def self.calculate(year, gross_income, options)
|
5
|
+
calculation_result = CalculationResult.new(year, gross_income, options)
|
6
|
+
calculation_result.calculate
|
7
|
+
calculation_result
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/lib/us_income_tax.rb
CHANGED
@@ -7,6 +7,15 @@ require_relative "us_income_tax/bracket"
|
|
7
7
|
require_relative "us_income_tax/calculation_result"
|
8
8
|
require_relative "us_income_tax/calculator"
|
9
9
|
|
10
|
+
# HSA
|
11
|
+
require_relative "us_income_tax/hsa/max_contribution_data_loader"
|
12
|
+
require_relative "us_income_tax/hsa/taxable_income_calculator"
|
13
|
+
require_relative "us_income_tax/hsa/calculation_result"
|
14
|
+
|
15
|
+
# DTO
|
16
|
+
require_relative "us_income_tax/dto/calculation_result_options"
|
17
|
+
require_relative "us_income_tax/dto/calculation_result_options_hsa"
|
18
|
+
|
10
19
|
module USIncomeTax
|
11
20
|
class Error < StandardError; end
|
12
21
|
# Your code goes here...
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: us_income_tax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Kim
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Calculate US federal income tax. The gem can calculate how much tax should
|
14
14
|
be paid for different tax brackets
|
@@ -24,12 +24,18 @@ files:
|
|
24
24
|
- README.md
|
25
25
|
- Rakefile
|
26
26
|
- data/federal_tax_bracket.json
|
27
|
+
- data/hsa_max_contribution.json
|
27
28
|
- lib/us_income_tax.rb
|
28
29
|
- lib/us_income_tax/bracket.rb
|
29
30
|
- lib/us_income_tax/bracket_library.rb
|
30
31
|
- lib/us_income_tax/bracket_loader.rb
|
31
32
|
- lib/us_income_tax/calculation_result.rb
|
32
33
|
- lib/us_income_tax/calculator.rb
|
34
|
+
- lib/us_income_tax/dto/calculation_result_options.rb
|
35
|
+
- lib/us_income_tax/dto/calculation_result_options_hsa.rb
|
36
|
+
- lib/us_income_tax/hsa/calculation_result.rb
|
37
|
+
- lib/us_income_tax/hsa/max_contribution_data_loader.rb
|
38
|
+
- lib/us_income_tax/hsa/taxable_income_calculator.rb
|
33
39
|
- lib/us_income_tax/scenario.rb
|
34
40
|
- lib/us_income_tax/version.rb
|
35
41
|
- sig/us_income_tax.rbs
|