Skip to content

Conversation

@Krashaune
Copy link

@Krashaune Krashaune commented Feb 20, 2018

Grocery Store

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Response Instructor Feedback
Why is it useful to put classes inside modules? It is useful for Namespacing and organizing code so it is easy to understand what classes are associated with what.
What is accomplished with raise ArgumentError? A raised ArgumentError when an invalid argument is entered and there is not a specific exception message.
Why do you think we made the .all & .find methods class methods? Why not instance methods? They were class methods so they could access all instance variables and be used throughout the class This is not quite correct. Class variables can't access instance variables - what if there was more than one instance? Which version of the variables would it use?

Instead, class methods are useful when a behavior is associated with the whole class, instead of one particular instance. If we made .all or .find instance methods, then you would have to have an instance of Order to get all the orders, which doesn't make much sense. With a class method, all you need is to know that there is a thing called Order, you don't already have to have one.
Why does it make sense to use inheritance for the online order? Because the online order shares multiple attributes of the order class, and instead of copy an pasting information from one class to another inheritance allows you to use the same initialize attributes as well as add to them if need be.
Did the presence of automated tests change the way you thought about the problem? How? Yes and no, at some points it made me focus on passing the tests and not worrying about what the program was printing out, but, other times when I was having trouble writing the tests I needed to switch and think about the problem differently.

…r of products, is added to collection of products tests
… the list and replaced the entire list with snickers, 2.50
…e final hash of items is assigne to the products variable.
@droberts-sea
Copy link

Grocery Store

What We're Looking For

Feature Feedback
Baseline
Answered comprehension questions yes - see instructor feedback above
Used Git Regularly yes
Wave 1
All provided tests pass
Using the appropriate attr_ for instance variables
Wave 2
All stubbed tests are implemented fully and pass yes, aside from the mismatch on what the products should look like
Appropriately parses the product data from CSV file in Order.all no - see inline
Used CSV library only in Order.all (not in Order.find) yes
Used Order.all to get order list in Order.find yes
Wave 3
All stubbed tests are implemented fully and pass no - much of this is missing
Used inheritance in the initialize for online order yes
Used inheritance for the total method in online order some - see inline
Use CSV library only in OnlineOrder.all N/A
Used all to get order list in find N/A
Appropriately searches for Customer orders in find_by_customer N/A
Additional Notes

This is a decent start, and I see a lot of things I like. The tests you wrote for wave 2 look great aside from the product list, and it feels like you were on the right track with inheritance for wave 3. However, like we discussed on Slack it seems like you're still having a lot of trouble working through problems, going from an idea of what you want to working Ruby code. In this project, the result is that much of your logic for waves 1 and 2 doesn't really work, and you didn't have the time to address wave 3 fully.

Given all that, I think it would be wise to match you with a tutor for some extra one-on-one support. Hopefully that will help give you the boost you need to really feel confident on these projects. I'll speak with Charles about it, and you can expect him to reach out to you soon.

require 'awesome_print'
require 'pry'
require 'csv'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get access to Order in this fill, you need to put a require_relative 'order' here.

else
return true
@products[:product_name] = product_price
before_count = @products.count

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting a return on line 31 prevents the rest of the method from running! The product is never added to the order.

In fact, because you've got the if statement above, we can shorten this else statement to

else
  @products[:product_name] = product_price
  return true
end

No need to worry about the counts.

products = line[1].split(";")#[1]
products.each do |items|# take the string split at the : and assign them to key value pairs
# ap products
products = items.split(":")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using a different name for the result of this split. Calling it products will override the products you've defined outside.

product_price = items[1].to_i

# products[product_name] = product_price
orders << Order.new(id, products)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this logic will work for .all. Here's what I'm seeing:

  • items is a single value, a string that looks like "banana:3.99"
  • products is an array with two values that looks like ['banana', 3.99]
  • On lines 62 and 63, you split the name and the price into separate local variables, but these are never used
  • On line 66, you make an Order inside the inner loop. That means you'll create an order for every product-price pair, for every line in the CSV file, more than we want.

You are, however, quite close. If you were to make the following changes, this code would look good:

  • Between line 55 and 56, create a new local variable products_hash = {}
  • Instead of creating an order for each pair in the list, add the pair to the products_hash
    • Replace line 66 with products_hash[product_name] = product_price
  • After the inner loop (between 67 and 68), create a new Order from the id and the products_hash and add it to the list

if order.id == id
return order
else
return nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this return nil makes sense inside of the loop. That means as soon as it hits an order that's not the one we're looking for, it'll return! Searching for anything other than the first order wouldn't work.

Instead, you could put the return nil after the loop. Your code then would effectively say, "If in all of that looping I didn't find the matching order and return it already, I will return nil now".


FILENAME = "support/orders.csv"


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of a constant to hold the file name


def initialize(id, products, status = :pending)
super(id, products)
@customer_id = customer_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of super here to keep this DRY.

# same as order except will add $10 shipping fee
def total
super()
return sum += 10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order for this to work, you'll need to keep track of the value you get from super. Something like:

def total
  sum = super()
  return sum + 10
end

super()
unless status == pending || status == paid
raise ArgumentError, "INVALID STATUS"
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want to make this check before the call to super.

# Arrange - feed information for method to work with

products_list = ["Slivered Almonds", "22.88"], ["Wholewheat flour", "1.93"],["Grape Seed Oil" , "74.9"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The product lists in orders you get from .all should have the same form as the hashes we saw in previous tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants