Class: Moneymarket::Account
- Inherits:
-
Object
- Object
- Moneymarket::Account
- Defined in:
- lib/moneymarket/core/account.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#frozen ⇒ Object
readonly
Returns the value of attribute frozen.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #available ⇒ Object
- #deposit(_amount) ⇒ Object
- #freeze(_amount) ⇒ Object
-
#initialize(_user, _currency, _total, _frozen, _ref = nil) ⇒ Account
constructor
A new instance of Account.
- #unfreeze(_amount) ⇒ Object
- #withdraw(_amount) ⇒ Object
Constructor Details
#initialize(_user, _currency, _total, _frozen, _ref = nil) ⇒ Account
Returns a new instance of Account.
5 6 7 8 9 10 11 |
# 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 |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
3 4 5 |
# File 'lib/moneymarket/core/account.rb', line 3 def currency @currency end |
#frozen ⇒ Object (readonly)
Returns the value of attribute frozen.
3 4 5 |
# File 'lib/moneymarket/core/account.rb', line 3 def frozen @frozen end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
3 4 5 |
# File 'lib/moneymarket/core/account.rb', line 3 def ref @ref end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/moneymarket/core/account.rb', line 3 def total @total end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'lib/moneymarket/core/account.rb', line 3 def user @user end |
Instance Method Details
#available ⇒ Object
13 14 15 |
# File 'lib/moneymarket/core/account.rb', line 13 def available total - frozen end |
#deposit(_amount) ⇒ Object
30 31 32 33 |
# 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) ⇒ Object
17 18 19 20 21 22 |
# 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) ⇒ Object
24 25 26 27 28 |
# 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) ⇒ Object
35 36 37 38 39 |
# 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 |