Skip to content

Bank Accounts - Wave 2 #42

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 8 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
31 changes: 21 additions & 10 deletions BankAccounts.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require 'csv'

module Bank
class Account
attr_reader :balance, :owner, :id
def initialize(owner, balance = 0)
@id = rand(1000000)
@balance = balance
if balance < 0
attr_reader :ident, :balance, :open_date
attr_accessor :owner
def initialize(ident, balance, open_date, owner = nil)
@ident = ident.to_i
@balance = balance.to_i
if @balance < 0
raise ArgumentError, "Not a valid initial balance!"
end
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z")
@owner = owner
end
def withdraw(amount)
Expand All @@ -20,7 +24,18 @@ def withdraw(amount)
def deposit(amount)
@balance = @balance + amount
end
def self.all
CSV.read("./support/accounts.csv").map do |row|
Bank::Account.new(row[0], row[1], row[2])
end
end
def self.find(id)
self.all.find do |account|
account.ident == id
end
end
end

class Owner
attr_reader :id, :first, :last, :street_address, :city, :state, :zip
def initialize(owner_info)
Expand All @@ -35,8 +50,4 @@ def initialize(owner_info)
end
end

owner_info = {first: "Kelly", last: "Devlin", street_address: "4538 46th Ave SW", city: "Seattle",
state: "WA", zip: "98116"}
owner = Bank::Owner.new(owner_info)
account = Bank::Account.new(owner)
puts "Account ##{account.id} is owned by #{account.owner.first} #{account.owner.last} (owner id##{account.owner.id})."
Bank::Account.find(1213)
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