class Moneymarket::Account
Attributes
currency[R]
frozen[R]
ref[R]
total[R]
user[R]
Public Class Methods
new(_user, _currency, _total, _frozen, _ref = nil)
click to toggle source
# File lib/moneymarket/core/account.rb, line 5 def initialize(_user, _currency, _total, _frozen, _ref = nil) @user = _user @currency = _currency @total = _total @frozen = _frozen @ref = _ref end
Public Instance Methods
available()
click to toggle source
# File lib/moneymarket/core/account.rb, line 13 def available total - frozen end
deposit(_amount)
click to toggle source
# File lib/moneymarket/core/account.rb, line 30 def deposit(_amount) raise ArgumentError, 'amount to deposit must be positive' if _amount < 0 @total += _amount end
freeze(_amount)
click to toggle source
# File lib/moneymarket/core/account.rb, line 17 def freeze(_amount) # TODO: check currency? raise ArgumentError, 'amount to freeze must be positive' if _amount < 0 raise ArgumentError, 'trying to freeze more than is available' if _amount > available @frozen += _amount end
unfreeze(_amount)
click to toggle source
# File lib/moneymarket/core/account.rb, line 24 def unfreeze(_amount) raise ArgumentError, 'amount to unfreeze must be positive' if _amount < 0 raise ArgumentError, 'trying to unfreeze more than is frozen' if _amount > frozen @frozen -= _amount end
withdraw(_amount)
click to toggle source
# File lib/moneymarket/core/account.rb, line 35 def withdraw(_amount) raise ArgumentError, 'amount to withdraw must be positive' if _amount < 0 raise ArgumentError, 'not enough funds to withdraw' if _amount > available @total -= _amount end