-
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 - Macaria #31
base: master
Are you sure you want to change the base?
Conversation
… file to include corresponding test
|
||
# Build Customer class, instantiate readers for instance variables. | ||
class Customer | ||
attr_reader :id, :all_customers, :email, :address |
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.
While I personally would make these all attr_reader
s 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| |
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.
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:
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] |
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.
Constant! 🎉
|
||
# Validate that input was among the included possible statuses. Raise error, otherwise. | ||
if !VALID_STATUSES.include?(fulfillment_status) | ||
raise ArgumentError.new("Invalid Status") |
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.
It's helpful for debugging to say what status was invalid.
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 |
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.
The body of your if
was on its own line, but not the else (which makes it easy to overlook).
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) |
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 use round
for this:
return (sprintf("%.2f", total_amount).to_f) | |
return total_amount.round(2) |
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. 😀 |
Grocery Store
Congratulations! You're submitting your assignment.
Comprehension Questions
raise ArgumentError
?.all
&.find
methods class methods? Why not instance methods?Order
andCustomer
. Is this relation one-to-one, one-to-many, or something else? How does that compare to the Solar System project?Order
andCustomer
tracked in the CSV file? How is it tracked in your program? Why might these be different?