Skip to content

Commit 66b7751

Browse files
committed
Merge pull request #32 from rmtolmach/rmt/master
Primary requirements for wave 2
2 parents ae74107 + 3621fc9 commit 66b7751

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

BankAccounts.rb

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
module Bank
22
class Account
3-
attr_reader :balance # makes it so the user can only see their balance, not change it.
4-
def initialize(id, balance)
3+
require 'csv' #is this in the right place?
4+
5+
attr_reader :id, :balance, :open_date # makes it so the user can only see their balance, not change it.
6+
def initialize(id, balance, open_date)
57
@id = id
68
@balance = balance
7-
raise ArgumentError.new("Permission Denied") if balance < 0
9+
@open_date = open_date
10+
raise ArgumentError.new("Permission Denied") if balance < "0"
811
end
912

1013
# Once a new Owner is created, the variable holding the hash is passed in as 'person parameter'
@@ -26,6 +29,32 @@ def deposit(amnt_deposited)
2629
@balance = @balance + amnt_deposited #Return the updated account balance.
2730
puts "Your current balance is: #{@balance}"
2831
end
32+
33+
# This method returns all of the accounts in one array as Account instances.
34+
def self.all
35+
# reads the csv and puts it in an array.
36+
@csv_info = CSV.read("./support/accounts.csv")
37+
# Makes an empty array
38+
account_all = []
39+
# goes through each array
40+
@csv_info.each do |l|
41+
# Creates a new instance of an Account and pushes the info from
42+
# index 0..2 into my empty array.
43+
account_all.push(Account.new(l[0], l[1], l[2]))
44+
end
45+
# Prints the new array.
46+
account_all
47+
end
48+
49+
# This method takes in an ID
50+
def self.find(id)
51+
# 'self' contains the account_all information. I use the find method to
52+
# go through each thing in the aray...
53+
self.all.find do |a|
54+
# ...and checks to see if anything in the array equals the id passed in.
55+
a.id.to_i == id
56+
end
57+
end
2958
end
3059

3160
# Owner sets up the code to accept the important info in a hash. Feed info in irb.

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)