-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
399 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,3 +5,5 @@ gem 'rake' | |
gem 'rspec' | ||
gem 'coveralls', require: false | ||
gem 'capybara' | ||
gem 'twilio-ruby' | ||
gem 'smarter_csv' |
This file contains 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 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 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,2 @@ | ||
require './lib/takeaway' | ||
ta = Takeaway.new |
This file contains 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,30 @@ | ||
#displays a list of dishes with prices | ||
require 'smarter_csv' | ||
require 'words' | ||
|
||
class Menu | ||
|
||
attr_reader :dishes | ||
|
||
def initialize | ||
@dishes = parse | ||
end | ||
|
||
def display | ||
Words.menu_header | ||
dishes.each do |plate,price| | ||
puts "#{plate.capitalize}: £#{price}" | ||
end | ||
Words.line | ||
end | ||
|
||
private | ||
|
||
def parse | ||
data = SmarterCSV.process('./rubysushi.csv') | ||
dishes = {} | ||
data.each {|dish| dishes[dish[:plate]] = dish[:price]} | ||
dishes | ||
end | ||
|
||
end |
This file contains 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,46 @@ | ||
#takes selection of dishes | ||
#looks up in menu to ensure dish is valid | ||
require_relative 'takeaway' | ||
require_relative 'menu' | ||
require_relative 'words' | ||
|
||
class Order | ||
|
||
attr_reader :items, :total, :menu | ||
|
||
def initialize(menu = Menu.new) | ||
@items = {} | ||
@total = 0 | ||
@menu = menu | ||
end | ||
|
||
def take_order | ||
Words.order_prompt | ||
loop do | ||
Words.dish_selection_prompt | ||
dish = gets.chomp.downcase | ||
until menu.dishes.key?(dish) || dish == "done" | ||
Words.not_a_dish | ||
dish = gets.chomp.downcase | ||
end | ||
break if dish == "done" | ||
Words.quantity_selection_prompt | ||
quantity = gets.chomp.to_i | ||
add_to_order(dish, quantity) | ||
calculate(dish, quantity) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_writer :total | ||
|
||
def calculate(dish, quantity) | ||
self.total += menu.dishes[dish] * quantity | ||
end | ||
|
||
def add_to_order(dish, quantity) | ||
items[dish] = quantity | ||
end | ||
|
||
end |
This file contains 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,15 @@ | ||
require 'twilio-ruby' | ||
|
||
class Sms | ||
attr_reader :confirmation_sms | ||
TWILIO_ACCOUNT_SID = "ACf5913cffd02b007aa9462769e71beb1d" | ||
TWILIO_AUTH_TOKEN = "[AUTH TOKEN]" | ||
def confirmation_sms | ||
client = Twilio::REST::Client.new(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN) | ||
|
||
client.messages.create( | ||
from: "+441872672068", | ||
to: "[PHONE NUMBER]", | ||
body: "Thank you! Your order was placed and will be delivered before #{(Time.now + 60*60).strftime("%H:%M")} 🍣") | ||
end | ||
end |
This file contains 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,67 @@ | ||
#prints messages to user, calls methods in correct order | ||
|
||
require_relative 'menu' | ||
require_relative 'order' | ||
require_relative 'sms' | ||
require_relative 'words' | ||
|
||
class Takeaway | ||
|
||
attr_reader :menu, :order | ||
|
||
def initialize(menu = Menu.new) | ||
@menu = menu | ||
welcome | ||
total_correct? | ||
end | ||
|
||
def total_correct? | ||
breakdown | ||
answer = gets.chomp.downcase | ||
if answer == "y" | ||
correct | ||
elsif answer == "n" | ||
incorrect | ||
else | ||
Words.invalid_input | ||
total_correct? | ||
end | ||
end | ||
|
||
private | ||
|
||
def correct | ||
sms = Sms.new | ||
sms.confirmation_sms | ||
Words.thankyou_message | ||
end | ||
|
||
def incorrect | ||
Words.incorrect_order_options | ||
answer = gets.chomp.downcase | ||
until answer == "n" || answer == "q" | ||
Words.invalid_yesno_input | ||
answer = gets.chomp.downcase | ||
end | ||
answer == "n" ? start_over : abort(Words.exit_message) | ||
end | ||
|
||
def start_over | ||
Takeaway.new | ||
end | ||
|
||
def welcome(order = Order.new) | ||
Words.greeting | ||
menu.display | ||
@order = order | ||
order.take_order | ||
end | ||
|
||
def breakdown | ||
Words.breakdown_header | ||
order.items.each {|plate,price| puts "#{price}x #{plate.capitalize} @ £#{menu.dishes[plate]}"} | ||
puts "Total: £#{order.total}" | ||
Words.breakdown_correct? | ||
end | ||
|
||
end |
Oops, something went wrong.