-
Notifications
You must be signed in to change notification settings - Fork 2k
Slava's Takeaway Challenge #2229
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
Open
amfibiya17
wants to merge
5
commits into
makersacademy:main
Choose a base branch
from
amfibiya17:main
base: main
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
5 commits
Select commit
Hold shift + click to select a range
77a918c
class Dishes
amfibiya17 3c7ab07
order class plus tests for select_dishes method
amfibiya17 6f6a3eb
Order class methods delete_dishes, check_total, confirm_order
amfibiya17 9190f7d
Text class and tests completed
amfibiya17 4ed9fdd
README.md, order class (sms when order condirmed)
amfibiya17 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,22 @@ | ||
| class Dishes | ||
| attr_reader :menu | ||
|
|
||
| def initialize | ||
| @menu = [ | ||
| { name: "Diet (not really) Pizza", price: 5.99 }, | ||
| { name: "Make me fat Pizza", price: 6.99 }, | ||
| { name: "Easy-Peasy Pizza", price: 7.99 }, | ||
| { name: "Hold my beer Pizza", price: 8.99 }, | ||
| { name: "Once in a lifetime Pizza", price: 9.99 } | ||
| ] | ||
| end | ||
|
|
||
| def show_dishes | ||
| @menu.each_with_index { |meal, index| puts "#{index + 1}. #{meal[:name]} £#{meal[:price]}" } | ||
| @menu | ||
| end | ||
|
|
||
| def dish_available?(index) | ||
| @menu[index] != nil | ||
| end | ||
| end |
This file contains hidden or 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,10 @@ | ||
| require_relative 'text' | ||
| require 'twilio-ruby' | ||
| require 'dotenv' | ||
|
|
||
| account_sid = ENV['ACCOUNT_SID'] | ||
| auth_token = ENV['AUTH_TOKEN'] | ||
| client = Twilio::REST::Client.new(account_sid, auth_token) | ||
|
|
||
| text = Text.new(client) | ||
| text.send_message |
This file contains hidden or 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,40 @@ | ||
| require_relative 'dishes' | ||
| require_relative 'text' | ||
|
|
||
| class Order | ||
| attr_reader :basket, :menu, :dishes, :complete, :text | ||
|
|
||
| def initialize | ||
| @basket = Array.new(0) | ||
| dishes = Dishes.new | ||
| @menu = dishes.menu | ||
| @dishes = dishes | ||
| @complete = false | ||
| @text = Text.new | ||
| end | ||
|
|
||
| def select_dishes(index) | ||
| raise "Order already confirmed and can't be changed." if @complete | ||
| raise "Dish is not available. Please choose a different dish." if !dishes.dish_available?(index - 1) | ||
| @basket << @menu[index - 1] | ||
| end | ||
|
|
||
| def delete_dishes(index) | ||
| raise "Order already confirmed and can't be changed." if @complete | ||
| @basket.delete(@menu[index - 1]) | ||
| @basket | ||
| end | ||
|
|
||
| def check_total | ||
| total = 0 | ||
| @basket.each { |meal| total += meal[:price] } | ||
| return "£#{total}" | ||
| end | ||
|
|
||
| def confirm_order | ||
| @complete = true | ||
| puts "Order complete." | ||
| text.send_message | ||
| return check_total | ||
| end | ||
| end | ||
This file contains hidden or 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,32 @@ | ||
| require 'twilio-ruby' | ||
| require 'dotenv' | ||
|
|
||
| class Text | ||
| TIME_FORMAT = "%k:%M" | ||
|
|
||
| attr_reader :mobile | ||
|
|
||
| def initialize | ||
| @mobile = ENV['CUST_NUMBER'] | ||
| end | ||
|
|
||
| def send_message | ||
| account_sid = ENV['ACCOUNT_SID'] | ||
| auth_token = ENV['AUTH_TOKEN'] | ||
| client = Twilio::REST::Client.new(account_sid, auth_token) | ||
|
|
||
| begin | ||
| client.messages.create( | ||
| body: "Thank you! Your order was placed and will be delivered before #{delivery_time}", | ||
| to: @mobile, | ||
| from: ENV['TWILIO_NUMBER'] | ||
| ) | ||
| puts message.sid | ||
| rescue | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This empty rescue block just swallows any errors, without telling you / the user about them. I'd encourage you to look into whether you can rescue a more specific error, and at least |
||
| end | ||
| end | ||
|
|
||
| def delivery_time | ||
| time = (Time.now + 60 * 60).strftime(TIME_FORMAT) | ||
| end | ||
| end | ||
This file contains hidden or 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,31 @@ | ||
| require 'dishes' | ||
|
|
||
| describe Dishes do | ||
| it "creates an instance of the class" do | ||
| expect(subject).to be_instance_of(Dishes) | ||
| end | ||
|
|
||
| describe "#show_dishes" do | ||
| it "prints a list of dishes with prices" do | ||
| expect { subject.show_dishes }.to output(<<~output | ||
| 1. Diet (not really) Pizza £5.99 | ||
| 2. Make me fat Pizza £6.99 | ||
| 3. Easy-Peasy Pizza £7.99 | ||
| 4. Hold my beer Pizza £8.99 | ||
| 5. Once in a lifetime Pizza £9.99 | ||
| output | ||
| ).to_stdout | ||
| end | ||
| end | ||
|
|
||
| describe "#dishes_available?" do | ||
| it "returns true when dishes available" do | ||
| expect(subject.dish_available?(1)).to eq(true) | ||
| end | ||
|
|
||
| it "returns true when dishes available" do | ||
| expect(subject.dish_available?(10)).to eq false | ||
| end | ||
| end | ||
| 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.
I don't think all of these attribute readers are needed. Extra available state from inside our objects can cause problems sometimes - especially if someone else is going to use our code as an API (like a gem) - if we allow them to use more parts of our code, they are likely to rely upon them, and we have to work to maintain that too.