Skip to content

Primary requirements for wave 2 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions BankAccounts.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module Bank
class Account
attr_reader :balance # makes it so the user can only see their balance, not change it.
def initialize(id, balance)
require 'csv' #is this in the right place?

attr_reader :id, :balance, :open_date # makes it so the user can only see their balance, not change it.
def initialize(id, balance, open_date)
@id = id
@balance = balance
raise ArgumentError.new("Permission Denied") if balance < 0
@open_date = open_date
raise ArgumentError.new("Permission Denied") if balance < "0"
end

# Once a new Owner is created, the variable holding the hash is passed in as 'person parameter'
Expand All @@ -26,6 +29,32 @@ def deposit(amnt_deposited)
@balance = @balance + amnt_deposited #Return the updated account balance.
puts "Your current balance is: #{@balance}"
end

# This method returns all of the accounts in one array as Account instances.
def self.all
# reads the csv and puts it in an array.
@csv_info = CSV.read("./support/accounts.csv")
# Makes an empty array
account_all = []
# goes through each array
@csv_info.each do |l|
# Creates a new instance of an Account and pushes the info from
# index 0..2 into my empty array.
account_all.push(Account.new(l[0], l[1], l[2]))
end
# Prints the new array.
account_all
end

# This method takes in an ID
def self.find(id)
# 'self' contains the account_all information. I use the find method to
# go through each thing in the aray...
self.all.find do |a|
# ...and checks to see if anything in the array equals the id passed in.
a.id.to_i == id
end
end
end

# Owner sets up the code to accept the important info in a hash. Feed info in irb.
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ Create an `Account` class which should have the following functionality:
- Add an `owner` property to each Account to track information about who owns the account.
- 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.

<!--

## Wave 2
### CSV Files!
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.
- 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
- Add the following **class** methods to your existing `Account` class
- `self.all` - returns a collection of `Account` instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications
- `self.find(id)` - returns an instance of `Account` where the value of the id field in the CSV matches the passed parameter
- Update the `Account` class to be able to handle all of these fields from the CSV file used as input.


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

Bank::Owner
The data, in order in the CSV, consists of:
**ID** - (Fixnum) a unique identifier for that Owner
**Last Name** - (String) the owner's last name
**First Name** - (String) the owner's first name
**Street Addess** - (String) the owner's street address
**City** - (String) the owner's city
**State** - (String) the owner's state

To create the relationship between the accounts and the owners use the `account_owners` CSV file.
The data for this file, in order in the CSV, consists of:
**Account ID** - (Fixnum) a unique identifier corresponding to an account
**Owner ID** - (Fixnum) a unique identifier corresponding to an owner

<!--
## Wave 3
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- An updated `initialize` method:
Expand Down
12 changes: 12 additions & 0 deletions support/account_owners.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1212,25
1213,24
1214,19
1215,14
1216,18
1217,15
15151,17
15152,16
15153,21
15154,20
15155,22
15156,23
12 changes: 12 additions & 0 deletions support/accounts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1212,1235667,1999-03-27 11:30:09 -0800
1213,66367,2010-12-21 12:21:12 -0800
1214,9876890,2007-09-22 11:53:00 -0800
1215,919191,2011-10-31 13:55:55 -0800
1216,100022,2000-07-07 15:07:55 -0800
1217,12323,2003-11-07 11:34:56 -0800
15151,9844567,1993-01-17 13:30:56 -0800
15152,34343434343,1999-02-12 14:03:00 -0800
15153,2134,2013-11-07 09:04:56 -0800
15154,43567,1996-04-17 08:44:56 -0800
15155,999999,1990-06-10 13:13:13 -0800
15156,4356772,1994-11-17 14:04:56 -0800
12 changes: 12 additions & 0 deletions support/owners.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
14,Morales,Wanda,9003 Gerald Hill,Honolulu,Hawaii
15,Foster,Shirley,79734 Namekagon Court,Tampa,Florida
16,Taylor,James,9 Portage Court,Winston Salem,North Carolina
17,Ross,Marilyn,0 Delaware Circle,Seattle,Washington
18,Gonzalez,Laura,310 Hauk Street,Springfield,Illinois
19,Cooper,Ruby,99 American Road,Atlanta,Georgia
20,Knight,Helen,3373 American Point,Charlotte,North Carolina
21,Bell,Jessica,06 Kenwood Hill,Lansing,Michigan
22,Sanders,Annie,8113 Sutherland Center,Everett,Washington
23,Berry,Shirley,7 Kings Pass,Cleveland,Ohio
24,King,Kevin,3499 Judy Center,Santa Monica,California
25,Clark,Kathleen,72984 Chive Hill,New York City,New York