Skip to content

Commit ffba141

Browse files
committed
Define oder_line, map out input options
1 parent 925b83c commit ffba141

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

lib/handle_input.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative 'item'
2+
require_relative 'order_line'
23

34
# HandleInput class
45
class HandleInput
@@ -12,5 +13,37 @@ def interpret(command)
1213
return unless ACTIONS.include?(command)
1314

1415
$stdout.print "#{command} \n"
16+
17+
if command == 'LIST'
18+
# list all availble items and package sizes
19+
end
20+
21+
return shop if command == 'SHOP'
22+
23+
if command == 'VIEW'
24+
# show invoice
25+
end
26+
27+
if command == 'EXIT'
28+
# exit
29+
end
30+
end
31+
32+
def shop
33+
# retrieve another input
34+
$stdout.print "Select qty and items, example: 3 watermelon \n"
35+
36+
input = gets.chomp
37+
38+
return if input.empty? #TODO: OR if it doesn't match a specific order pattern
39+
40+
# break it down into qty, item
41+
line = input.split(/\W+/)
42+
43+
# create the order_line
44+
order_line = OrderLine.new(line[0], line[1])
45+
46+
# return the order line
47+
$stdout.print "#{order_line.order_qty} #{order_line.order_item} \n"
1548
end
1649
end

lib/order_line.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# OrderLine class
2+
class OrderLine
3+
attr_reader :order_qty, :order_item
4+
5+
def initialize(order_qty, order_item)
6+
@order_qty = order_qty
7+
@order_item = order_item
8+
end
9+
end

spec/order_line_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'rspec'
2+
require 'spec_helper'
3+
require './lib/order_line'
4+
5+
describe OrderLine do
6+
describe '#initialize' do
7+
it 'should have a order_qty attribute which is an Integer' do
8+
instance = OrderLine.new(3, 'watermelon')
9+
10+
expect(instance.order_qty).to be_a Integer
11+
expect(instance.order_qty).to eq 3
12+
end
13+
14+
it 'should have a order_item attribute which is an instance of Item' do
15+
instance = OrderLine.new(3, Watermelon.new('watermelon'))
16+
17+
expect(instance.order_item).to be_a Item
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)