exercise done
This commit is contained in:
1 parent
7049ba14b4
commit
1736f62660
1 file changed
+32
-1
@@ -48,5 +48,36 @@
|
||||
# => { action: :invalid }
|
||||
|
||||
def parse_command(input)
|
||||
# À compléter.
|
||||
response = {}
|
||||
parts = input.strip.split
|
||||
|
||||
case parts[0]
|
||||
when "help"
|
||||
if parts.size == 1
|
||||
response[:action] = :help
|
||||
else
|
||||
response[:action] = :invalid
|
||||
end
|
||||
when "quit"
|
||||
if parts.size == 1
|
||||
response[:action] = :quit
|
||||
else
|
||||
response[:action] = :invalid
|
||||
end
|
||||
when "play"
|
||||
if parts.size == 2 && parts[1].match?(/\A\d+\z/) && parts[1].to_i > 0
|
||||
response[:action] = :play
|
||||
response[:card] = parts[1].to_i
|
||||
else
|
||||
response[:action] = :invalid
|
||||
end
|
||||
else
|
||||
response[:action] = :invalid
|
||||
end
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
print "Entrez une action : "
|
||||
input = gets.chomp
|
||||
puts parse_command(input)
|
||||
Reference in new issue
Block a user