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

Rupert #2221

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Rupert #2221

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ruby '3.0.2'

group :test do
gem 'rspec'
gem 'twilio-ruby'
gem 'simplecov', require: false, group: :test
gem 'simplecov-console', require: false, group: :test
end
Expand Down
34 changes: 34 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,37 @@ GEM
ast (2.4.2)
diff-lcs (1.4.4)
docile (1.4.0)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
jwt (2.3.0)
multipart-post (2.1.1)
nokogiri (1.13.3-arm64-darwin)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.2.0)
ast (~> 2.4.1)
racc (1.5.1)
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
Expand Down Expand Up @@ -36,6 +64,7 @@ GEM
rubocop-ast (1.11.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -48,6 +77,10 @@ GEM
simplecov_json_formatter (0.1.3)
terminal-table (3.0.1)
unicode-display_width (>= 1.1.1, < 3)
twilio-ruby (5.66.0)
faraday (>= 0.9, < 2.0)
jwt (>= 1.5, <= 2.5)
nokogiri (>= 1.6, < 2.0)
unicode-display_width (2.0.0)

PLATFORMS
Expand All @@ -58,6 +91,7 @@ DEPENDENCIES
rubocop (= 1.20)
simplecov
simplecov-console
twilio-ruby

RUBY VERSION
ruby 3.0.2p107
Expand Down
17 changes: 17 additions & 0 deletions lib/TwilioTextMessenger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'twilio-ruby'

class TwilioTextMessenger
attr_reader :message, :call

def initialize
@message = message
account_sid = 'ACf27cbbcdf904e00bcf60428cfb4271c9'
auth_token = '18303ff4fddfac8208b8be0aab167886'
client = Twilio::REST::Client.new(account_sid, auth_token)
client.messages.create(
from: 'my twilio number',
to: 'my phone number',
body: "Thank you! Your order was placed and will be delivered before #{Time.now + 1*60*60}"
)
end
end
18 changes: 18 additions & 0 deletions lib/dish.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Dish

attr_accessor = :name, :price

def initialize(name, price)
@name = name
@price = price
end

def name
@name
end

def price
@price
end

end
28 changes: 28 additions & 0 deletions lib/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'dish'
require_relative 'order'

class Menu

attr_reader :order, :view_menu
attr_accessor :menu, :item_number

def initialize
@menu = []
end

def add_dish(name, price)
dish = Dish.new(name, price)
@menu.push(dish)
end

def menu
@menu
end

private

def view_order_numbers
@order_numbers
end

end
39 changes: 39 additions & 0 deletions lib/order.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require_relative 'dish'
require_relative 'menu'
require_relative 'TwilioTextMessenger'

class Order

attr_accessor :order

def initialize(menu, *item_number)
@order = []
@item_numbers = [*item_number]
@menu = menu
@total_price = 0
end

def submit_order
@order = @item_numbers.map { |dish| @menu.menu[dish-1]}
send_sms
end

def bill
prepare_bill
end

private
def calculate_order_price
@amounts = @order.map {|dish| dish.instance_variable_get(:@price)}
@amounts.each { |amount| @total_price+=amount}
"Total to pay: £#{@total_price}"
end

def prepare_bill
@order.each { |dish| puts "#{dish.name}: £#{dish.price}"}
end

def send_sms
TwilioTextMessenger.new
end
end
7 changes: 7 additions & 0 deletions spec/TwilioTextMessenger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'TwilioTextMessenger'

describe TwilioTextMessenger do
# it "should send text" do
# expect(subject).to include("Thank you! Your order was placed and will be delivered before 18:52")
# end
end
11 changes: 11 additions & 0 deletions spec/dish_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'dish'

describe Dish do
dish = Dish.new("Korma", 8)
it '#name should retun the name of the dish' do
expect(dish.name).to be_a(String)
end
it '#price should return the price of the dish' do
expect(dish.price).to be_a(Integer)
end
end
15 changes: 15 additions & 0 deletions spec/menu_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'menu'

describe Menu do
it '#view_menu will return the list of dishes available' do
subject.add_dish("Fish",9)
subject.add_dish("Korma",8)
expect(subject.menu).to be_a(Array)
end

it "#add dish will allow use to pick as many dishes as they want" do
20.times {subject.add_dish("Korma",8)}
expect(subject.menu.count).to eq 20
end

end
20 changes: 20 additions & 0 deletions spec/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'order'
require 'menu'

describe Order do
menu = Menu.new
menu.add_dish("Fish",9)
menu.add_dish("Korma",8)
order = Order.new(menu,1,2)
order.submit_order
it "#submit_order should put chosen dishes into an order" do
expect(order.order[0]).to be_a(Dish)
expect(order.order[1]).to be_a(Dish)
end

it "#bill to return a bill with names and price of each item" do
expect(order.bill).to include(:dish => 'Fish')
expect(order.bill).to include(:price => 8)
end

end