Skip to content

Jimmy Lyons take-away challenge - #2233

Open
jimmy-lyons wants to merge 14 commits into
makersacademy:mainfrom
jimmy-lyons:main
Open

Jimmy Lyons take-away challenge#2233
jimmy-lyons wants to merge 14 commits into
makersacademy:mainfrom
jimmy-lyons:main

Conversation

@jimmy-lyons

@jimmy-lyons jimmy-lyons commented May 3, 2022

Copy link
Copy Markdown

Jimmy Lyons

User stories

Please list which user stories you've implemented (delete the ones that don't apply).

  • User story 1: "I would like to see a list of dishes with prices"
  • User story 2: "I would like to be able to select some number of several available dishes"
  • User story 3: "I would like to check that the total I have been given matches the sum of the various dishes in my order"
  • User story 4: "I would like to receive a text such as "Thank you! Your order was placed and will be delivered before 18:52" after I have ordered"

README checklist

Does your README contains instructions for

  • how to install,
  • how to run,
  • and how to test your code?

Comment thread README_JL.md
@@ -0,0 +1,80 @@
## Takeaway Weekdend Challenge

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good glaven this is a comprehensive and highly helpful README

Comment thread lib/homepage.rb
end

def see_restaurant_menu(restaurant)
@currently_viewed_menu = Menu.new(restaurant)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a nice bit of abstraction (think that's the word) - didn't occur to me at all

Comment thread lib/menu.rb
end

def csv_to_hash
@file.readlines.each do |line|

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wish I could comment intelligently on how you've handled this with a .csv file, but it's way beyond my understanding

Comment thread lib/order.rb
@current_order.push({item => @menu.menu_hash[item]})
end

def remove(item)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This feels a little complicated for one method,, but I'm sure there are good reasons for that

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you use encapsulation to move some of these long operations into a private method and make the main body of the code more readable?

Comment thread lib/order.rb
if current_order.empty?
@printed_order
else
format_order

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice SRP

Comment thread lib/order.rb
def order_total
@total = 0
calculate_total
return "£#{'%.2f' % @total}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oo, nice rounding

Comment thread lib/text.rb
require 'twilio-ruby'

class Text
def initialize(number, acc_sid, a_token)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure I understand the thinking here, particularly with the method commented out in order.rb. Would be good to chat it through

@SamButton12 SamButton12 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi Jimmy, Lovely work on this challenge. I especially like that you've really gone beyond the user stories to add CSV files, use different types of restaurants and added a homepage.

Comment thread spec/homepage_spec.rb
expect(subject.display_restaurants).to be_an_instance_of(String)
end

# it 'should list restaurants with corresponding csv files' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that best practice is to delete redundant code and comments before pull requesting. (nit-picking)

Comment thread spec/order_spec.rb
expect(order.current_order.length).to eq 1
end

it 'should only add items from the initialised menu' do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could make this slightly more readable. You already have the #add describe block, so probably dont need the 'add' in the it block (nit-picking)

Comment thread lib/homepage.rb
end

def see_restaurant_menu(restaurant)
@currently_viewed_menu = Menu.new(restaurant)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would initializing a new menu and order help here?

Comment thread lib/order.rb
@current_order.push({item => @menu.menu_hash[item]})
end

def remove(item)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you use encapsulation to move some of these long operations into a private method and make the main body of the code more readable?

@eoinmakers eoinmakers left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good implementation of the Takeaway challenge, well done. You've clearly demonstrated the objectives of the week.

There's a good range of unit tests here, but in some cases all you need to do is verify that other methods have been called. https://stackoverflow.com/questions/21262309/rspec-how-to-test-if-a-method-was-called For example, where a method is responsible for calling a private method, or a method of another class.

Comment thread lib/homepage.rb
@order = nil
end

def display_restaurants

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This feels like an addition to the project specs, which you should be careful about - trying to adhere as closely to the spec as possible is always a priority for projects & tech tests.

Comment thread lib/menu.rb
# Can't figure out how to put csv files in a separate folder.
# It always seems to return an error.

class Menu

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In this project, something as simple as a Hash or array of Dish objects is fine to represent the menu.

Comment thread lib/order.rb
array_item = {item => @menu.menu_hash[item]}
fail "Input error: Item not in current order." unless @current_order.include? array_item
i = current_order.find_index(array_item)
@current_order.delete_at(i)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deleting an item from the order is also an additional feature! It's definitely functional, but adds unnecessary complexity to your development and end result.

Comment thread lib/order.rb
# def confirm_order(number, acc_sid, a_token)
# # method required to send order to restaurant
# sms = Text.new(number, acc_sid, a_token)
# end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We try to remove commented out code / test snippets before opening PRs for tidiness.

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.

4 participants