Class: Banks::Account
- Inherits:
-
Object
- Object
- Banks::Account
- Defined in:
- lib/banks/account.rb
Constant Summary collapse
- CREDIT =
Types
"Credit"- DEBIT =
"Debit"- UNKNOWN =
"Unknown"
Instance Attribute Summary collapse
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#link ⇒ Object
Returns the value of attribute link.
-
#name ⇒ Object
Returns the value of attribute name.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #convert_to_debit(account) ⇒ Object
-
#merge_accounts(accounts) ⇒ Object
accounts - Array of accounts.
- #to_s ⇒ Object
Instance Attribute Details
#balance ⇒ Object
Returns the value of attribute balance.
3 4 5 |
# File 'lib/banks/account.rb', line 3 def balance @balance end |
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/banks/account.rb', line 3 def link @link end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/banks/account.rb', line 3 def name @name end |
#transactions ⇒ Object
Returns the value of attribute transactions.
3 4 5 |
# File 'lib/banks/account.rb', line 3 def transactions @transactions end |
#type ⇒ Object
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 account account.type = DEBIT account.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 |account| if account.type == CREDIT convert_to_debit account end @transactions.merge_array account.transactions end @type = DEBIT transactions.sort_by_date end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/banks/account.rb', line 10 def to_s transactions.to_s end |