forked from Ada-C6/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_account.rb
52 lines (45 loc) · 1.12 KB
/
bank_account.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'csv'
module Bank
class Account
attr_accessor :id, :balance
def initialize(id, balance, open_date)
@balance = balance
@id = id
@open_date = open_date
if @balance < 0
raise (ArgumentError)
end
#puts "Your Bank Account Number is #{ @id } and your balance is #{ @balance }."
# assigns initial balance >= 0
end
def self.all
all_accounts = []
CSV.read('support/accounts.csv', 'r').each do |line|
all_accounts << self.new(line[0], line[1].to_i, line[2])
end
return all_accounts
end
def self.find(id)
all.each do |acc|
if acc.id == id
return acc
end
end
end
def deposit(funds)
# takes user input and += from balance
return @balance += funds
end
def withdraw(funds)
# takes user input and -= from balance
if @balance - funds < 0
puts "You have insufficient funds."
return @balance
else
return @balance -= funds
# return new_balance
# new_balance >= $0.00, if not, raise ArgumentError
end
end
end
end