Skip to content

Commit 2cd87c4

Browse files
committed
Merge pull request #35 from emgord/erg/master
Wave 2 Bank Account
2 parents 3f3a620 + e4f8dee commit 2cd87c4

File tree

5 files changed

+115
-28
lines changed

5 files changed

+115
-28
lines changed

BankAccounts.rb

+60-26
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
require 'chronic'
2+
require 'csv'
3+
14
module Bank
25

36
class Account
47

5-
attr_reader :balance, :owner
8+
attr_reader :balance, :owner, :account_id
69

7-
def initialize(account_id, initial_balance = 0)
8-
@account_id = account_id
9-
@balance = check_initial_balance(initial_balance)
10+
def initialize(account_id, initial_balance, open_date)
11+
@account_id = account_id.to_i
12+
@balance = check_initial_balance(initial_balance.to_i)
13+
@open_date = Chronic.parse(open_date)
1014
end
1115

1216
def withdraw(amount)
@@ -30,6 +34,34 @@ def check_initial_balance(initial_balance)
3034
end
3135
end
3236

37+
def self.all
38+
account_array = CSV.read("support/accounts.csv")
39+
40+
account_array.map! do |account|
41+
Bank::Account.new(account[0],account[1],account[2])
42+
end
43+
return account_array
44+
end
45+
46+
def self.find(id)
47+
Bank::Account.all.find do |account|
48+
account.account_id == id
49+
end
50+
end
51+
52+
def self.add_relationships
53+
add_owner_array = CSV.read("support/account_owners.csv")
54+
accounts_with_owners = []
55+
56+
add_owner_array.each do |key|
57+
account = Bank::Account.find(key[0].to_i)
58+
owner = Bank::Owner.find(key[1].to_i)
59+
account.add_owner(owner)
60+
accounts_with_owners.push(account)
61+
end
62+
return accounts_with_owners
63+
end
64+
3365
def add_owner(owner)
3466
@owner = owner
3567
end
@@ -38,30 +70,32 @@ def add_owner(owner)
3870

3971
class Owner
4072

41-
attr_reader :first_name ,:last_name, :address_line_1, :address_line_2, :city, :state, :zip, :email
42-
43-
def initialize(owner_hash)
44-
@first_name = owner_hash[:first_name]
45-
@last_name = owner_hash[:last_name]
46-
@address_line_1 = owner_hash[:address_line_1]
47-
@address_line_2 = owner_hash[:address_line_2]
48-
@city = owner_hash[:city]
49-
@state = owner_hash[:state]
50-
@zip = owner_hash[:zip]
51-
@email = owner_hash[:email]
73+
attr_reader :owner_id, :last_name, :first_name, :street_address, :city, :state
74+
75+
def initialize(owner_id, last_name, first_name, street_address, city, state)
76+
@owner_id = owner_id.to_i
77+
@last_name = last_name
78+
@first_name = first_name
79+
@street_address = street_address
80+
@city = city
81+
@state = state
5282
end
5383

54-
end
84+
def self.all
85+
owner_array = CSV.read("support/owners.csv")
5586

56-
end
87+
owner_array.map! do |owner|
88+
Bank::Owner.new(owner[0],owner[1],owner[2],owner[3],owner[4], owner[5])
89+
end
90+
return owner_array
91+
end
5792

58-
test_owner_hash = {
59-
first_name: "Joe",
60-
last_name: "Scmoe",
61-
address_line_1: "123 Apple Street",
62-
city: "Seattle",
63-
state: "WA",
64-
zip: "98103",
65-
93+
def self.find(id)
94+
Bank::Owner.all.find do |owner|
95+
owner.owner_id == id
96+
end
97+
end
6698

67-
}
99+
end
100+
101+
end

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ Create an `Account` class which should have the following functionality:
3535
- Add an `owner` property to each Account to track information about who owns the account.
3636
- The `Account` can be created with an `owner`, OR you can create a method that will add the `owner` after the `Account` has already been created.
3737

38-
<!--
38+
3939
## Wave 2
4040
### CSV Files!
41+
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
42+
- For example, manually choose the data from the first line of the CSV file and ensure you can create a new instance of your Account using that data
4143
- Add the following **class** methods to your existing `Account` class
4244
- `self.all` - returns a collection of `Account` instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications
4345
- `self.find(id)` - returns an instance of `Account` where the value of the id field in the CSV matches the passed parameter
44-
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
46+
4547

4648
#### CSV Data File
4749
Bank::Account
@@ -57,6 +59,21 @@ Create an `Account` class which should have the following functionality:
5759
- `self.all` - returns a collection of `Owner` instances, representing all of the Owners described in the CSV. See below for the CSV file specifications
5860
- `self.find(id)` - returns an instance of `Owner` where the value of the id field in the CSV matches the passed parameter
5961

62+
Bank::Owner
63+
The data, in order in the CSV, consists of:
64+
**ID** - (Fixnum) a unique identifier for that Owner
65+
**Last Name** - (String) the owner's last name
66+
**First Name** - (String) the owner's first name
67+
**Street Addess** - (String) the owner's street address
68+
**City** - (String) the owner's city
69+
**State** - (String) the owner's state
70+
71+
To create the relationship between the accounts and the owners use the `account_owners` CSV file.
72+
The data for this file, in order in the CSV, consists of:
73+
**Account ID** - (Fixnum) a unique identifier corresponding to an account
74+
**Owner ID** - (Fixnum) a unique identifier corresponding to an owner
75+
76+
<!--
6077
## Wave 3
6178
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
6279
- An updated `initialize` method:

support/account_owners.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1212,25
2+
1213,24
3+
1214,19
4+
1215,14
5+
1216,18
6+
1217,15
7+
15151,17
8+
15152,16
9+
15153,21
10+
15154,20
11+
15155,22
12+
15156,23

support/accounts.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
1212,1235667,1999-03-27 11:30:09 -0800
2+
1213,66367,2010-12-21 12:21:12 -0800
3+
1214,9876890,2007-09-22 11:53:00 -0800
4+
1215,919191,2011-10-31 13:55:55 -0800
5+
1216,100022,2000-07-07 15:07:55 -0800
6+
1217,12323,2003-11-07 11:34:56 -0800
7+
15151,9844567,1993-01-17 13:30:56 -0800
8+
15152,34343434343,1999-02-12 14:03:00 -0800
9+
15153,2134,2013-11-07 09:04:56 -0800
10+
15154,43567,1996-04-17 08:44:56 -0800
11+
15155,999999,1990-06-10 13:13:13 -0800
12+
15156,4356772,1994-11-17 14:04:56 -0800

support/owners.csv

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
14,Morales,Wanda,9003 Gerald Hill,Honolulu,Hawaii
2+
15,Foster,Shirley,79734 Namekagon Court,Tampa,Florida
3+
16,Taylor,James,9 Portage Court,Winston Salem,North Carolina
4+
17,Ross,Marilyn,0 Delaware Circle,Seattle,Washington
5+
18,Gonzalez,Laura,310 Hauk Street,Springfield,Illinois
6+
19,Cooper,Ruby,99 American Road,Atlanta,Georgia
7+
20,Knight,Helen,3373 American Point,Charlotte,North Carolina
8+
21,Bell,Jessica,06 Kenwood Hill,Lansing,Michigan
9+
22,Sanders,Annie,8113 Sutherland Center,Everett,Washington
10+
23,Berry,Shirley,7 Kings Pass,Cleveland,Ohio
11+
24,King,Kevin,3499 Judy Center,Santa Monica,California
12+
25,Clark,Kathleen,72984 Chive Hill,New York City,New York

0 commit comments

Comments
 (0)