Skip to content

Commit 62ef411

Browse files
committed
Merge pull request #43 from CShekta/cas/master
Cas/master
2 parents d357666 + ba1d1a4 commit 62ef411

File tree

5 files changed

+127
-27
lines changed

5 files changed

+127
-27
lines changed

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:

bank_account.rb

+72-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
require 'CSV'
2+
#TO DO
3+
#Use .map for the all method? since it returns an array you don't need to create one
14
module Bank
25

36
class Account
4-
attr_reader :balance, :id, :owner
5-
def initialize(balance = 0, id = 7383092, owner = nil)
6-
@balance = balance
7+
attr_accessor :balance, :id, :owner, :open_date
8+
def initialize(id, balance, open_date, owner = nil)
9+
@balance = balance.to_i
710
@id = 7383092
811
@owner = owner
9-
if balance < 0
12+
@open_date = open_date
13+
if @balance < 0
1014
raise ArgumentError, "Accounts cannot be opened with negative money"
1115
end
1216
end
@@ -33,37 +37,80 @@ def check_balance
3337
def add_owner(owner)
3438
@owner = owner
3539
end
40+
41+
def self.all
42+
acct_csv_array = CSV.read("support/accounts.csv")
43+
account_array = []
44+
acct_csv_array.each do |line|
45+
account_array.push(Account.new(line[0], line[1], line[2]))
46+
end
47+
return account_array
48+
end
49+
50+
def self.find(id)
51+
acct_csv_array = CSV.read("support/accounts.csv")
52+
match_line = acct_csv_array.find do |line|
53+
line[0].to_i == id
54+
end
55+
specific_account = Account.new(match_line[0], match_line[1], match_line[2])
56+
end
57+
58+
def self.associate_everything
59+
account_and_owner_csv = CSV.read("support/account_owners.csv")
60+
everything_array = []
61+
account_and_owner_csv.each do |line|
62+
each_account = Bank::Account.find(line[0].to_i)
63+
each_owner = Bank::Owner.find(line[1].to_i)
64+
each_account.add_owner(each_owner)
65+
everything_array.push(each_account)
66+
end
67+
return everything_array
68+
end
3669
end
3770

3871
class Owner
39-
attr_reader :account, :first_name, :last_name, :address, :email, :owner_id
40-
def initialize(owner_hash)
72+
attr_reader :account, :owner_id, :last_name, :first_name, :address, :city, :state
73+
def initialize(id, last_name, first_name, address, city, state)
4174
@account = account
42-
@first_name = owner_hash[:first_name]
43-
@last_name = owner_hash[:last_name]
44-
@address = owner_hash[:address]
45-
@email = owner_hash[:email]
46-
@owner_id = owner_hash[:id]
75+
@first_name = first_name
76+
@last_name = last_name
77+
@address = address
78+
@owner_id = owner_id
4779
end
4880

4981
def who_da_owna
5082
puts "This account is owned by #{@first_name} #{@last_name} with #{@owner_id}"
5183
end
84+
85+
def self.all
86+
owner_csv_array = CSV.read("support/owners.csv")
87+
owner_array = []
88+
owner_csv_array.each do |line|
89+
owner_array.push(Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]))
90+
end
91+
return owner_array
92+
end
93+
94+
def self.find(id)
95+
owner_csv_array = CSV.read("support/owners.csv")
96+
match_line = owner_csv_array.find do |line|
97+
line[0].to_i == id
98+
end
99+
specific_owner = Owner.new(match_line[0], match_line[1], match_line[2], match_line[3], match_line[4], match_line[5])
100+
end
52101
end
53102
end
54103

55-
owner_hash = {
56-
first_name: "Winnie",
57-
last_name: "The Pooh",
58-
address: "Deep in the Hundred Acre Woods",
59-
60-
id: 2376423
61-
}
104+
# owner_hash = {
105+
# first_name: "Winnie",
106+
# last_name: "The Pooh",
107+
# address: "Deep in the Hundred Acre Woods",
108+
# email: "[email protected]",
109+
# id: 2376423
110+
# }
62111

63-
a = Bank::Account.new
64-
o = Bank::Owner.new(owner_hash)
65-
a.add_owner(o)
66-
puts "#{a.owner.first_name}"
67-
a.deposit(100)
68-
a.withdraw(50)
69-
a.withdraw(70)
112+
#a = Bank::Account.new("1212","1235667","1999-03-27 11:30:09 -0800")
113+
#a.check_balance
114+
#Bank::Account.all
115+
#o = Bank::Owner.new(owner_hash)
116+
#puts "#{a.owner.first_name}"

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)