Module: TresBot
- Defined in:
- lib/tres_bot.rb,
lib/tres_bot/version.rb
Defined Under Namespace
Classes: Robot
Constant Summary collapse
- VERSION =
"0.1"
Class Method Summary collapse
Class Method Details
.execute_command(robot, command) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tres_bot.rb', line 72 def self.execute_command(robot,command) @robot = robot command = command.split(' ') if command[0] != nil if command[0].downcase == 'place' if place_command_valid?(command) full_position = command[1].split(',') @robot.place(full_position) else puts "Your place command is invalid. Please try again." end elsif ['move', 'report','left','right'].include? command[0].downcase @robot.is_on_the_table ? @robot.send(command[0].downcase) : (puts "Put me on the table!") end end end |
.place_command_valid?(command) ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'lib/tres_bot.rb', line 64 def self.place_command_valid?(command) if command[1].nil? return false else command[1].downcase.gsub(/\s+/, "").match(/[0-4]+[,]+[0-9]+[,]+[a-z]{4,5}/) ? true : false end end |
.start ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/tres_bot.rb', line 90 def self.start puts 'Press Ctrl-C to exit' @robot = Robot.new until false == true command = gets execute_command(@robot,command) end end |