Class: MudratProjector::TaxCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/mudrat_projector/tax_calculator.rb

Defined Under Namespace

Modules: Year2012 Classes: Household, TransactionWrapper

Constant Summary collapse

HOUSEHOLD_TYPES =
%i(married_filing_jointly married_filing_separately single
head_of_household)
EXPENSE_ACCOUNT_ID =
:united_states_treasury

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(projector: nil, household: {}) ⇒ TaxCalculator

Returns a new instance of TaxCalculator.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mudrat_projector/tax_calculator.rb', line 83

def initialize projector: nil, household: {}
  @household   = Household.new(
    household.fetch(:filing_status),
    household.fetch(:exemptions),
  )
  @projector   = projector
  @values_hash = parse_yaml
  unless projector. EXPENSE_ACCOUNT_ID
    projector. EXPENSE_ACCOUNT_ID, type: :expense
  end
  unless projector. :owed_taxes
    projector. :owed_taxes, type: :liability
  end
end

Instance Attribute Details

#householdObject (readonly)

Returns the value of attribute household.



10
11
12
# File 'lib/mudrat_projector/tax_calculator.rb', line 10

def household
  @household
end

Class Method Details

.project(projector, to: end_date, household: nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/mudrat_projector/tax_calculator.rb', line 25

def self.project projector, to: end_date, household: nil
  tax_calculator = new projector: projector, household: household
  (projector.from.year..to.year).each do
    calculation = tax_calculator.calculate!
    yield calculation if block_given?
  end
  tax_calculator.projector
end

Instance Method Details

#calculate!Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/mudrat_projector/tax_calculator.rb', line 98

def calculate!
  end_of_calendar_year = Date.new year, 12, 31
  calculation = TaxCalculation.new projector, household, @values_hash
  next_projector = projector.project to: end_of_calendar_year, build_next: true do |transaction|
    calculation << TransactionWrapper.new(self, transaction).tap(&:calculate!)
  end
  final_transaction = Transaction.new(
    date: end_of_calendar_year,
    debit:  { amount: calculation.taxes_owed, account_id: EXPENSE_ACCOUNT_ID },
    credit: { amount: calculation.taxes_owed, account_id: :owed_taxes },
  )
  projector.apply_transaction final_transaction
  @projector = next_projector
  @values_hash = parse_yaml
  calculation
end

#yearObject



115
116
117
# File 'lib/mudrat_projector/tax_calculator.rb', line 115

def year
  projector.from.year
end