Class: Banks::Account

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

Constant Summary collapse

CREDIT =

Types

"Credit"
DEBIT =
"Debit"
UNKNOWN =
"Unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#balanceObject

Returns the value of attribute balance.



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

def balance
  @balance
end

Returns the value of attribute link.



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

def link
  @link
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#transactionsObject

Returns the value of attribute transactions.



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

def transactions
  @transactions
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#convert_to_debit(account) ⇒ Object



27
28
29
30
31
32
# File 'lib/banks/account.rb', line 27

def convert_to_debit 
  .type = DEBIT
  .transactions.each do|transaction|
    transaction.amount = transaction.amount*-1
  end
end

#merge_accounts(accounts) ⇒ Object

accounts - Array of accounts.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/banks/account.rb', line 15

def merge_accounts (accounts)
  @transactions = TransactionArray.new
  accounts.each do ||
    if .type == CREDIT
      convert_to_debit 
    end
    @transactions.merge_array .transactions
  end
  @type = DEBIT
  transactions.sort_by_date
end

#to_sObject



10
11
12
# File 'lib/banks/account.rb', line 10

def to_s
  transactions.to_s
end