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
Leaves - Dominique Taylor #29
Open
dtaylor73
wants to merge
2
commits into
Ada-C12:master
Choose a base branch
from
dtaylor73: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
2 commits
Select commit
Hold shift + click to select a range
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,42 @@ | ||
require 'csv' | ||
|
||
class Customer | ||
attr_reader :id | ||
attr_accessor :email, :address | ||
|
||
def initialize(id, email, address = {}) | ||
@id = id | ||
@email = email | ||
@address = address | ||
end | ||
|
||
def self.all | ||
#this is a class method bc it calls a method on itself | ||
customer_array = [] | ||
|
||
customer_data = CSV.read("data/customers.csv", headers: true).map(&:to_h) | ||
|
||
customer_data.each do |info| | ||
customer = Customer.new( info["id"].to_i, info["email"], { | ||
street: info["street"], | ||
city: info["city"], | ||
state: info["state"], | ||
zip: info["zip"] | ||
}) | ||
customer_array << customer | ||
end | ||
return customer_array | ||
end | ||
|
||
def self.find(id) | ||
Customer.all.each do |customer_instance| | ||
return customer_instance if id == customer_instance.id | ||
# when you're in a class method, you have to type | ||
# "customer_instance.id" instead of just @id to get the | ||
# integer. @id only has access to the class when it is inside | ||
# an instance method. Self.find is a class method. | ||
end | ||
return nil | ||
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,92 @@ | ||
require 'csv' | ||
require 'pry' | ||
|
||
class Order | ||
attr_reader :id | ||
attr_accessor :products, :customer, :fulfillment_status | ||
|
||
def initialize(id, products, customer, fulfillment_status = :pending) | ||
# initialize is a special instance method of .new | ||
@id = id | ||
@products = products | ||
@customer = customer | ||
@fulfillment_status = fulfillment_status | ||
|
||
fulfillment_status_array = [:pending, :paid, :processing, :shipped, :complete] | ||
# fulfillment_status must equal one of these options, but is set to | ||
# :pending default. | ||
|
||
if fulfillment_status_array.include?(fulfillment_status) == false | ||
raise ArgumentError, "You must provide a valid fulfillment status | ||
#{fulfillment_status_array.join(",")}" | ||
end | ||
end | ||
|
||
def total | ||
products_total_cost = @products.values.sum * 1.075 | ||
return ('%.2f' % (products_total_cost)).to_f | ||
# Got the percentage by 7.5/100 and then | ||
# adding 1 to 0.075 | ||
end | ||
|
||
def add_product(product_name, price) | ||
if @products.keys.include?(product_name) == false | ||
@products[product_name] = price | ||
elsif | ||
raise ArgumentError, "You must provide a product with a different | ||
name" | ||
end | ||
end | ||
|
||
def self.all | ||
orders_data = CSV.read("data/orders.csv", headers: true).map(&:to_h) | ||
|
||
order_array = [] | ||
|
||
orders_data.each_with_index do |products, index| | ||
product_variable = Order.parse_products(orders_data) | ||
order = Order.new(products["id"].to_i, | ||
product_variable[index], Customer.find(products["customer_id"].to_i), products["status"].to_sym) | ||
order_array << order | ||
end | ||
return order_array | ||
end | ||
|
||
def self.find(id) | ||
Order.all.each do |order_instance| | ||
return order_instance if id == order_instance.id | ||
end | ||
return nil | ||
end | ||
|
||
def self.parse_products(orders) | ||
products_array = [] | ||
product_hash = {} | ||
|
||
orders.each do |products1| | ||
product_hash = {} | ||
products_split_by_semicolon = products1["products"].split(';') | ||
|
||
products_split_by_colon = products_split_by_semicolon.map do |products2| | ||
products2.split(':') | ||
end | ||
|
||
products_split_by_colon.each do |products3| | ||
product_key = products3[0] | ||
product_value = products3[1] | ||
product_hash[product_key] = product_value.to_f | ||
end | ||
products_array.push(product_hash) | ||
end | ||
products_array | ||
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 |
---|---|---|
|
@@ -32,12 +32,11 @@ | |
end | ||
end | ||
|
||
# TODO: remove the 'x' in front of this block when you start wave 2 | ||
xdescribe "Customer Wave 2" do | ||
describe "Customer Wave 2" do | ||
describe "Customer.all" do | ||
it "Returns an array of all customers" do | ||
customers = Customer.all | ||
|
||
expect(customers.length).must_equal 35 | ||
customers.each do |c| | ||
expect(c).must_be_kind_of Customer | ||
|
@@ -61,7 +60,6 @@ | |
|
||
it "Returns accurate information about the last customer" do | ||
last = Customer.all.last | ||
|
||
expect(last.id).must_equal 35 | ||
expect(last.email).must_equal "[email protected]" | ||
expect(last.address[:street]).must_equal '7513 Kaylee Summit' | ||
|
@@ -79,7 +77,7 @@ | |
expect(first.id).must_equal 1 | ||
end | ||
|
||
it "Can find the last customer from the CSV" do | ||
it "Can find the last customer from the CSV" do | ||
last = Customer.find(35) | ||
|
||
expect(last).must_be_kind_of Customer | ||
|
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.
I like that you made a helper here!