class SaveTheMonth::ExpectedBalance
Attributes
final_date[RW]
initial_amount[RW]
initial_date[RW]
movements[RW]
periodical_strategies[RW]
Public Class Methods
new()
click to toggle source
# File lib/expected_balance.rb, line 50 def initialize self.movements = [] self.periodical_strategies = PaymentPeriodicalStrategies.new end
Public Instance Methods
add_charge(name, &perform)
click to toggle source
# File lib/expected_balance.rb, line 55 def add_charge(name, &perform) movements << make_movement(:charge, name, &perform) end
add_payment(name, &perform)
click to toggle source
# File lib/expected_balance.rb, line 59 def add_payment(name, &perform) movements << make_movement(:payment, name, &perform) end
add_timed_charge(name, amount, date)
click to toggle source
# File lib/expected_balance.rb, line 67 def add_timed_charge(name, amount, date) movements << make_timed_movement(name, amount, date) end
add_timed_payment(name, amount, date)
click to toggle source
# File lib/expected_balance.rb, line 63 def add_timed_payment(name, amount, date) movements << make_timed_movement(name, -amount, date) end
Private Instance Methods
kind_for(amount)
click to toggle source
# File lib/expected_balance.rb, line 88 def kind_for(amount) amount > 0 ? :charge : :payment end
make_movement(type, name, &perform)
click to toggle source
# File lib/expected_balance.rb, line 73 def make_movement(type, name, &perform) strategy = periodical_strategies.instance_eval(&perform) amount = type == :payment ? -strategy.amount : strategy.amount movement = PeriodicalMovement.new(Movement.new(type, name, amount)) movement.can_perform_strategy = strategy.can_perform movement end
make_timed_movement(name, amount, date)
click to toggle source
# File lib/expected_balance.rb, line 82 def make_timed_movement(name, amount, date) movement = DailyRestrictedMovement.new(Movement.new(kind_for(amount), name, amount)) movement.date = date movement end