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
Branches - Brianna K #40
Open
brikemp
wants to merge
6
commits into
Ada-C12:master
Choose a base branch
from
brikemp: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
6 commits
Select commit
Hold shift + click to select a range
37af58d
Wave 1 complete
brikemp 8971585
Wave 2 in progress, 1 test for cutomer still failing
brikemp 61becfa
Wave 2 Complete without Optional part finished
brikemp 5c95ea9
Wave 2 Optional finished
brikemp cf9e4e5
Wave 3 added for orders
brikemp 179b8e3
Wave 2 Tests for Order added
brikemp 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Customer | ||
require 'csv' | ||
|
||
attr_reader :id | ||
attr_accessor :email, :address | ||
|
||
|
||
|
||
def initialize(id, email, address) | ||
@id = id | ||
@email = email | ||
@address = address | ||
end | ||
|
||
def self.all | ||
all_customers = [] | ||
customer_data = CSV.open('data/customers.csv', headers:false).map(&:to_a) | ||
customer_data.each do |customer| | ||
parameter1 = customer[0].to_i | ||
parameter2 = customer[1] | ||
parameter3 = {} | ||
parameter3[:street] = customer[2] | ||
parameter3[:city] = customer[3] | ||
parameter3[:state] = customer[4] | ||
parameter3[:zip] = customer[5] | ||
temp = Customer.new(parameter1, parameter2, parameter3) | ||
all_customers.push(temp) | ||
end | ||
return all_customers | ||
end | ||
|
||
def self.find(id) | ||
customers = self.all | ||
customers.each do |customer| | ||
if customer.id == id | ||
return customer | ||
end | ||
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,106 @@ | ||
class Order | ||
|
||
attr_reader :id, :fulfillment_status, :customer, :products | ||
|
||
def initialize(id, products, customer, fulfillment_status = :pending) | ||
|
||
raise ArgumentError.new("Not a valid status") unless [:pending, :paid, :processing, :shipped, :complete].include? fulfillment_status | ||
|
||
@id = id | ||
@products = products | ||
@customer = customer | ||
@fulfillment_status = fulfillment_status | ||
|
||
end | ||
|
||
def total() | ||
cost_of_items = @products.values.sum | ||
cost_of_items *= 1.075 | ||
return cost_of_items.round(2) | ||
end | ||
|
||
def add_product(product_name, price) | ||
if @products.key?(product_name) | ||
raise ArgumentError.new("This item has already been included") | ||
else | ||
@products[product_name]= price | ||
end | ||
end | ||
|
||
def remove_product(product_name, price) | ||
if @products.key?(product_name) == false | ||
raise ArgumentError.new("This item has not yet been included") | ||
else | ||
@products.delete(product_name) | ||
end | ||
end | ||
|
||
def self.all | ||
all_orders = [] | ||
order_data = CSV.open('data/orders.csv', headers:false).map(&:to_a) | ||
order_data.each do |order| | ||
parameter1 = order[0].to_i | ||
parameter3 = order[2].to_i | ||
parameter4 = order[3].to_sym | ||
|
||
product_string = order[1].split(';') | ||
parameter2 = {} | ||
product_string.each do |row| | ||
temp = row.split(':') | ||
parameter2[temp[0]] = temp[1].to_f | ||
end | ||
temp = Order.new(parameter1, parameter2, parameter3, parameter4) | ||
all_orders.push(temp) | ||
end | ||
return all_orders | ||
end | ||
|
||
def self.find(id) | ||
orders = self.all | ||
orders.each do |order| | ||
if order.id == id | ||
return order | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
def self.find_by_customer(customer_id) | ||
orders = self.all | ||
customers_orders = [] | ||
orders.each do |order| | ||
if order.customer == customer_id | ||
customers_orders.push(order) | ||
end | ||
end | ||
return customers_orders | ||
end | ||
|
||
|
||
def self.save(filename) | ||
result = self.all | ||
CSV.open(filename, "w") do |csv| | ||
result.each do |row| | ||
current_order = {} | ||
current_order[:id] = row.id | ||
current_order_products = row.products | ||
product_string = "" | ||
count = 1 | ||
current_order_products.each do |item, cost| | ||
length = current_order_products.length | ||
product = item + ':' + cost.to_s | ||
product_string.concat(product) | ||
if count < length | ||
product_string.concat(';') | ||
count += 1 | ||
end | ||
end | ||
current_order[:products] = product_string | ||
current_order[:customer] = row.customer | ||
current_order[:fulfillment_status] = row.fulfillment_status | ||
csv << current_order.values | ||
end | ||
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
require 'minitest/reporters' | ||
require 'minitest/skip_dsl' | ||
|
||
require_relative '../lib/customer' | ||
require_relative '../lib/customer' | ||
|
||
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
||
|
@@ -15,53 +15,52 @@ | |
state: "WA", | ||
zip: "98101" | ||
}.freeze | ||
|
||
describe "#initialize" do | ||
it "Takes an ID, email and address info" do | ||
cust = Customer.new(ID, EMAIL, ADDRESS) | ||
|
||
expect(cust).must_respond_to :id | ||
expect(cust.id).must_equal ID | ||
|
||
expect(cust).must_respond_to :email | ||
expect(cust.email).must_equal EMAIL | ||
|
||
expect(cust).must_respond_to :address | ||
expect(cust.address).must_equal ADDRESS | ||
end | ||
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 | ||
|
||
expect(c.id).must_be_kind_of Integer | ||
expect(c.email).must_be_kind_of String | ||
expect(c.address).must_be_kind_of Hash | ||
end | ||
end | ||
|
||
it "Returns accurate information about the first customer" do | ||
first = Customer.all.first | ||
|
||
expect(first.id).must_equal 1 | ||
expect(first.email).must_equal "[email protected]" | ||
expect(first.address[:street]).must_equal "71596 Eden Route" | ||
expect(first.address[:city]).must_equal "Connellymouth" | ||
expect(first.address[:state]).must_equal "LA" | ||
expect(first.address[:zip]).must_equal "98872-9105" | ||
end | ||
|
||
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' | ||
|
@@ -70,22 +69,22 @@ | |
expect(last.address[:zip]).must_equal '64529-2614' | ||
end | ||
end | ||
|
||
describe "Customer.find" do | ||
it "Can find the first customer from the CSV" do | ||
first = Customer.find(1) | ||
|
||
expect(first).must_be_kind_of Customer | ||
expect(first.id).must_equal 1 | ||
end | ||
|
||
it "Can find the last customer from the CSV" do | ||
last = Customer.find(35) | ||
|
||
expect(last).must_be_kind_of Customer | ||
expect(last.id).must_equal 35 | ||
end | ||
|
||
it "Returns nil for a customer that doesn't exist" do | ||
expect(Customer.find(53145)).must_be_nil | ||
end | ||
|
Oops, something went wrong.
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.
This is another example where I'd suggest coming up with more descriptive variable names.