Skip to content
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 - Macaria #31

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Branches - Macaria #31

wants to merge 6 commits into from

Conversation

mdove92
Copy link

@mdove92 mdove92 commented Aug 26, 2019

Grocery Store

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Response
What is accomplished with raise ArgumentError? It exits out of the program if arguments aren't entered, or formatted correctly.
Why do you think we made the .all & .find methods class methods? Why not instance methods? '.all' and '.find' are class methods as they need access to every one of the orders or customers in order to do their formatting and searching. They do not take information from only one instance of our classes.
Think about the relation between Order and Customer. Is this relation one-to-one, one-to-many, or something else? How does that compare to the Solar System project? I think that the relation between "Customer" and "Order" is one-to-many. One customer may make many orders, but an order only has one customer. It is similar to the Solar System project, as a system could have many planets, but a planet exists in only one solar system.
How is the relation between Order and Customer tracked in the CSV file? How is it tracked in your program? Why might these be different? Orders are not tracked at all in the customer CSV file. In the order CSV file they are tracked in one place as customer id. The link is tenuous, as the customer id in the order file does not explicitly contain any of the other customer information. In
Did the presence of automated tests change the way you thought about the problem? How? The automated tests gave me clues as to how I should write my code. Using tests allowed for me to be more comfortable raising exceptions. Running rake also helped me to consistently refactor my code while staying firmly within the scope of the project.


# Build Customer class, instantiate readers for instance variables.
class Customer
attr_reader :id, :all_customers, :email, :address

Choose a reason for hiding this comment

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

While I personally would make these all attr_readers in my own code the spec did say to make everything but id read and write.

It's not a big deal though, and I'm not sure if we maybe want to update the assignment.

def self.all
all_customers = []
array_array_customers = CSV.read("data/customers.csv")
array_array_customers.each do |customer|

Choose a reason for hiding this comment

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

array_array_customers is kind of an odd name, I would probably name it something like customer_rows instead.

Also, since you only reference it once you can simply inline the CSV.read and not bother naming it:

Suggested change
array_array_customers.each do |customer|
CSV.read("data/customers.csv").each do |customer|

# Build Order Class and instantiate instance variables include readers for all attributes
class Order
attr_reader :id, :products, :customer, :fulfillment_status
VALID_STATUSES = [:pending, :paid, :processing, :shipped, :complete]

Choose a reason for hiding this comment

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

Constant! 🎉


# Validate that input was among the included possible statuses. Raise error, otherwise.
if !VALID_STATUSES.include?(fulfillment_status)
raise ArgumentError.new("Invalid Status")

Choose a reason for hiding this comment

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

It's helpful for debugging to say what status was invalid.

Suggested change
raise ArgumentError.new("Invalid Status")
raise ArgumentError.new("Invalid Status: #{fulfillment_status}")

@products.each do |product, price|
if @products.empty?
total_amount = 0.0
else total_amount += price.to_f

Choose a reason for hiding this comment

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

The body of your if was on its own line, but not the else (which makes it easy to overlook).

Suggested change
else total_amount += price.to_f
else
total_amount += price.to_f

end
end
total_amount = (total_amount * 1.075)
return (sprintf("%.2f", total_amount).to_f)

Choose a reason for hiding this comment

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

You can use round for this:

Suggested change
return (sprintf("%.2f", total_amount).to_f)
return total_amount.round(2)

@kaidamasaki
Copy link

Well done! Aside from a few small things the only note I've got is that you could have saved yourself a little work by using some Enumerable methods. Good job though. 😀

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