Skip to content

Commit

Permalink
Define oder_line, map out input options
Browse files Browse the repository at this point in the history
  • Loading branch information
SelenaSmall committed Sep 2, 2017
1 parent 925b83c commit ffba141
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/handle_input.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'item'
require_relative 'order_line'

# HandleInput class
class HandleInput
Expand All @@ -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
9 changes: 9 additions & 0 deletions lib/order_line.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions spec/order_line_spec.rb
Original file line number Diff line number Diff line change
@@ -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.