Permalink
Browse files

Define oder_line, map out input options

  • Loading branch information...
SelenaSmall committed Sep 2, 2017
1 parent 925b83c commit ffba1411bafd814d9057501ade50c5c722d0a4c7
Showing with 62 additions and 0 deletions.
  1. +33 −0 lib/handle_input.rb
  2. +9 −0 lib/order_line.rb
  3. +20 −0 spec/order_line_spec.rb
@@ -1,4 +1,5 @@
require_relative 'item'
require_relative 'order_line'
# HandleInput class
class HandleInput
@@ -12,5 +13,37 @@ def interpret(command)
return unless ACTIONS.include?(command)
$stdout.print "#{command} \n"
if command == 'LIST'
# list all availble items and package sizes
end
return shop if command == 'SHOP'
if command == 'VIEW'
# show invoice
end
if command == 'EXIT'
# exit
end
end
def shop
# retrieve another input
$stdout.print "Select qty and items, example: 3 watermelon \n"
input = gets.chomp
return if input.empty? #TODO: OR if it doesn't match a specific order pattern
# break it down into qty, item
line = input.split(/\W+/)
# create the order_line
order_line = OrderLine.new(line[0], line[1])
# return the order line
$stdout.print "#{order_line.order_qty} #{order_line.order_item} \n"
end
end
@@ -0,0 +1,9 @@
# OrderLine class
class OrderLine
attr_reader :order_qty, :order_item
def initialize(order_qty, order_item)
@order_qty = order_qty
@order_item = order_item
end
end
@@ -0,0 +1,20 @@
require 'rspec'
require 'spec_helper'
require './lib/order_line'
describe OrderLine do
describe '#initialize' do
it 'should have a order_qty attribute which is an Integer' do
instance = OrderLine.new(3, 'watermelon')
expect(instance.order_qty).to be_a Integer
expect(instance.order_qty).to eq 3
end
it 'should have a order_item attribute which is an instance of Item' do
instance = OrderLine.new(3, Watermelon.new('watermelon'))
expect(instance.order_item).to be_a Item
end
end
end

0 comments on commit ffba141

Please sign in to comment.