Class: Moneymarket::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/moneymarket/core/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#currencyObject (readonly)

Returns the value of attribute currency.



3
4
5
# File 'lib/moneymarket/core/account.rb', line 3

def currency
  @currency
end

#frozenObject (readonly)

Returns the value of attribute frozen.



3
4
5
# File 'lib/moneymarket/core/account.rb', line 3

def frozen
  @frozen
end

#refObject (readonly)

Returns the value of attribute ref.



3
4
5
# File 'lib/moneymarket/core/account.rb', line 3

def ref
  @ref
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/moneymarket/core/account.rb', line 3

def total
  @total
end

#userObject (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

#availableObject



13
14
15
# File 'lib/moneymarket/core/account.rb', line 13

def available
  total - frozen
end

#deposit(_amount) ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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