class FortuneTeller::Account::State
State
object used during simulation
Attributes
account_ref[R]
balance[RW]
date[RW]
Public Class Methods
new(start_date:, balance:, account_ref:)
click to toggle source
# File lib/fortuneteller/account.rb, line 23 def initialize(start_date:, balance:, account_ref:) @account_ref = account_ref @date = start_date @balance = balance @daily_growth_rate = 1.05**(1.0 / 365) # 5% annum end
Public Instance Methods
as_json(_options = nil)
click to toggle source
# File lib/fortuneteller/account.rb, line 46 def as_json(_options = nil) @balance end
credit(amount:, on:)
click to toggle source
# File lib/fortuneteller/account.rb, line 30 def credit(amount:, on:) pass_time(to: on) @balance += amount end
debit(amount:, on:)
click to toggle source
# File lib/fortuneteller/account.rb, line 35 def debit(amount:, on:) pass_time(to: on) @balance -= amount end
pass_time(to:)
click to toggle source
# File lib/fortuneteller/account.rb, line 40 def pass_time(to:) days = (to - @date).to_i @balance = (@balance * (@daily_growth_rate**days)).floor @date = to end