File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1
1
require_relative 'item'
2
+ require_relative 'order_line'
2
3
3
4
# HandleInput class
4
5
class HandleInput
@@ -12,5 +13,37 @@ def interpret(command)
12
13
return unless ACTIONS . include? ( command )
13
14
14
15
$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 "
15
48
end
16
49
end
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments