forked from AdaGold/grocery-store
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Daniela Sanchez - Leaves #28
Open
dnsanche
wants to merge
4
commits into
Ada-C12:master
Choose a base branch
from
dnsanche:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d05b68a
Finished Wave 1 w/tests passing
dnsanche 8f8a261
Finished Order Class, created class methods, completed given wave 2 t…
dnsanche 51c8053
Finished class methods for order, finished test for find class method…
dnsanche a2ec81a
Finished wave 2. Finished personal tests and all tests are still passing
dnsanche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id,email,street,city,state,zip | ||
1,[email protected],71596 Eden Route,Connellymouth,LA,98872-9105 | ||
2,[email protected],876 Kemmer Cove,East Luellatown,AL,21362 | ||
3,[email protected],96807 Cartwright Points,North Casper,MT,29547 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'csv' | ||
require 'awesome_print' | ||
require 'pry' | ||
|
||
class Customer | ||
|
||
attr_reader :id | ||
attr_accessor :email, :address | ||
|
||
def initialize(id, email, address) | ||
@id = id | ||
@email = email | ||
@address = address | ||
end | ||
|
||
def self.all | ||
#CSV is an array of Hashes were each hash is a customer. | ||
csv = CSV.read('/Users/dnsanche/ada/week3/grocery-store/data/customers.csv', headers: true).map(&:to_h) | ||
customers = [] | ||
|
||
csv.each do |customer| | ||
id = customer["id"].to_i | ||
email = customer["email"] | ||
address = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth thinking about how you would do this if you couldn't add headers to the '.csv' file. |
||
street: customer["street"], | ||
city: customer["city"], | ||
state: customer["state"], | ||
zip: customer["zip"], | ||
} | ||
customer = Customer.new(id,email,address) | ||
customers << customer | ||
end | ||
return customers | ||
end | ||
|
||
def self.find(id) | ||
if self.all[id-1] != nil | ||
return self.all[id-1] | ||
else | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require_relative 'customer' | ||
require 'csv' | ||
require 'awesome_print' | ||
|
||
class Order | ||
|
||
attr_reader :id | ||
attr_accessor :products, :customer, :fulfillment_status | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need |
||
|
||
def initialize(id, products, customer, fulfillment_status = :pending) | ||
@id = id | ||
@products = products | ||
@customer = customer | ||
@fulfillment_status = fulfillment_status | ||
|
||
if [:pending, :paid, :processing, :shipped, :complete].include?(fulfillment_status) == false | ||
raise ArgumentError.new('Invalid fulfillment status.') | ||
end | ||
end | ||
|
||
def add_product(product_name, product_price) | ||
if @products.include?(product_name) == true | ||
raise ArgumentError.new('Error. Product already exists in the list') | ||
else | ||
@products.store(product_name,product_price) | ||
end | ||
end | ||
|
||
def total | ||
total = 0 | ||
@products.each do |key, value| | ||
price = value*(1.075) | ||
total += price.round(2) | ||
end | ||
return total | ||
end | ||
|
||
def self.all | ||
csv = CSV.read("/Users/dnsanche/ada/week3/grocery-store/data/orders.csv", headers: true).map(&:to_h) | ||
orders = [] | ||
csv.each do |customer_order| | ||
id = customer_order["id"].to_i | ||
products = {} | ||
customer_order["products"].split(";").each do |product| | ||
name_and_price = product.split(":") | ||
products.store(name_and_price[0], name_and_price[1].to_f) | ||
end | ||
customer_id = customer_order["customer"].to_i | ||
customer = Customer.find(customer_id) | ||
fulfillment_status = customer_order["fulfillment_status"].to_sym | ||
orders << Order.new(id,products,customer,fulfillment_status) | ||
end | ||
return orders | ||
end | ||
|
||
def self.find(id) | ||
if Order.all[id-1] != nil | ||
return Order.all[id-1] | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't submit code that has the absolute path to github, because I don't have a folder called 'dnsanche'! Use the relative path moving forward.