-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c1cb3a
commit 828dc25
Showing
4 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
#!/usr/bin/ruby | ||
|
||
# Entry point | ||
require_relative './lib/handle_input' | ||
|
||
command = HandleInput.new | ||
|
||
$stdout.print "Would you like to LIST available products, SHOP, VIEW basket, EXIT without placing an order? \n" | ||
|
||
# Read user input | ||
loop do | ||
input = gets.chomp | ||
|
||
next if input.empty? | ||
|
||
unless 'EXIT'.match?(input) | ||
command.interpret(input) | ||
next | ||
end | ||
|
||
$stdout.print "Goodbye! \n" | ||
break | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require_relative 'item' | ||
|
||
# HandleInput class | ||
class HandleInput | ||
# Actions | ||
ACTIONS = %w[LIST SHOP VIEW EXIT].freeze | ||
|
||
# Interpret method | ||
# @param command [String] | ||
# @return | ||
def interpret(command) | ||
return unless ACTIONS.include?(command) | ||
|
||
$stdout.print "#{command} \n" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rspec' | ||
require 'spec_helper' | ||
require './lib/handle_input' | ||
|
||
describe HandleInput do | ||
describe '#interpret' do | ||
it 'should return nil unless command matches a value in ACTIONS array' do | ||
instance = HandleInput.new | ||
|
||
expect(instance.interpret('hello')).to be_nil | ||
end | ||
end | ||
end |