class FortuneTeller::SpendingStrategy::Transform

The transforms generated by job

Attributes

withdrawal[R]

Public Class Methods

new(holder:, date:, withdrawal:) click to toggle source
Calls superclass method FortuneTeller::TransformBase::new
# File lib/fortuneteller/spending_strategy.rb, line 41
def initialize(holder:, date:, withdrawal:)
  @withdrawal = withdrawal
  super(holder: holder, date: date)
end

Public Instance Methods

apply_to(state) click to toggle source
# File lib/fortuneteller/spending_strategy.rb, line 46
def apply_to(state)
  withdrawn = 0
  state.accounts.reject { |_k, a| a.balance.zero? }.each do |k, a|
    a.pass_time(to: @date)
    withdrawal = [a.balance, (@withdrawal - withdrawn)].min
    next if withdrawal.zero?
    make_withdrawal(state, a.account_ref.holder, k, withdrawal)
    withdrawn += withdrawal
    break if withdrawn == @withdrawal
  end
end

Private Instance Methods

make_withdrawal(state, holder, account, amount) click to toggle source
# File lib/fortuneteller/spending_strategy.rb, line 60
def make_withdrawal(state, holder, account, amount)
  state.apply_pretax_savings_withdrawal(
    date: @date,
    holder: holder,
    source: account,
    amount: amount
  )
end