diff --git a/Gemfile b/Gemfile index 606259a..cc840dd 100644 --- a/Gemfile +++ b/Gemfile @@ -54,8 +54,6 @@ gem "net-http" gem "data_migrate" -gem "callable" - group :development, :test do gem "capybara" gem "factory_bot_rails" diff --git a/Gemfile.lock b/Gemfile.lock index e5659ad..985be7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,7 +76,6 @@ GEM bootsnap (1.16.0) msgpack (~> 1.2) builder (3.2.4) - callable (0.0.5) capybara (3.38.0) addressable matrix @@ -305,7 +304,6 @@ PLATFORMS DEPENDENCIES annotate bootsnap - callable capybara data_migrate factory_bot_rails diff --git a/app/controllers/concerns/taxed_income.rb b/app/controllers/concerns/taxed_income.rb index b304953..f7e1982 100644 --- a/app/controllers/concerns/taxed_income.rb +++ b/app/controllers/concerns/taxed_income.rb @@ -3,22 +3,36 @@ module TaxedIncome extend ActiveSupport::Concern - included do - before_action :salary_income, :hourly_income - end - def build_taxed_income_vars! - @salary_taxed = tax_on_salary - @hourly_taxed = tax_on_hourly + @salary_taxed = net_income(annual_income: salary_income) + @hourly_taxed = net_income(annual_income: hourly_income) end private def salary_income - @salary_income ||= Income.find_by(income_type: "Salary") + @salary_income ||= Income.find_by(income_type: "Salary").weekly_income * 52 end def hourly_income - @hourly_income ||= Income.find_by(income_type: "Hourly") + @hourly_income ||= Income.find_by(income_type: "Hourly").weekly_income * 52 + end + + def fica_tax(income:) + @fica_tax ||= FicaTaxCalculator.call(income: income) + end + + def federal_tax(income:) + @federal_tax ||= FederalTaxCalculator.call(income: income) + end + + def state_tax(income:) + @state_tax ||= StateTaxCalculator.call(income: income) + end + + def net_income(annual_income:) + income = annual_income - (fica_tax(income:annual_income) + federal_tax(income:annual_income) + state_tax(income:annual_income)) + + @net_income ||= NetIncomeCalculator.call(annual_income: income) end end \ No newline at end of file diff --git a/app/services/federal_tax_calculator.rb b/app/services/federal_tax_calculator.rb index d01042b..fc843c1 100644 --- a/app/services/federal_tax_calculator.rb +++ b/app/services/federal_tax_calculator.rb @@ -5,7 +5,7 @@ def initialize(income:) self.income = income end - def callable + def call calculate end diff --git a/app/services/state_tax_calculator.rb b/app/services/state_tax_calculator.rb index 1f60cfb..4a4a825 100644 --- a/app/services/state_tax_calculator.rb +++ b/app/services/state_tax_calculator.rb @@ -1,17 +1,17 @@ class StateTaxCalculator include Callable - def initialize(state:, income:) + def initialize(income:) self.income = income - self.state = state end + # Colorado state tax rate is 4.4% def call income * 0.044 end private - attr_accessor :income, :state + attr_accessor :income end \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index f800e9e..2028ce3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,6 +23,10 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.0 + # Load in all modules + config.autoload_paths << Rails.root.join('lib', 'modules') + config.eager_load_paths << Rails.root.join('lib', 'modules') + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files diff --git a/lib/modules/callable.rb b/lib/modules/callable.rb new file mode 100644 index 0000000..862c578 --- /dev/null +++ b/lib/modules/callable.rb @@ -0,0 +1,9 @@ +module Callable + extend ActiveSupport::Concern + + class_methods do + def call(**args) + new(**args).call + end + end +end \ No newline at end of file