Class: TFClient::CommandParser

Inherits:
Object
  • Object
show all
Defined in:
lib/textflight-client/command_parser.rb

Constant Summary collapse

DIRECTION_MAP =
{
  n: "6",
  ne: "7",
  e: "4",
  se: "2",
  s: "1",
  sw: "0",
  w: "3",
  nw: "5"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:) ⇒ CommandParser

Returns a new instance of CommandParser.



25
26
27
# File 'lib/textflight-client/command_parser.rb', line 25

def initialize(command:)
  @command = command
end

Instance Attribute Details

#commandObject (readonly)

0: 315 degrees, X=-1, Y=-1 (northwest) 1: 0 degrees, X=0, Y=-1 (north) 2: 45 degrees, X=1, Y=-1 (northeast) 3: 270 degrees, X=-1, Y=0 (west) 4: 90 degrees, X=1, Y=0 (east) 5: 225 degrees, X=-1, Y=1 (southwest) 6: 180 degrees, X=0, Y=-1 (south) 7: 135 degrees, X=1, Y=-1 (southeast)



24
25
26
# File 'lib/textflight-client/command_parser.rb', line 24

def command
  @command
end

Instance Method Details

#parseObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/textflight-client/command_parser.rb', line 29

def parse
  if @command == "quit" || @command == "exit"
    return "exit"
  end

  direction = DIRECTION_MAP[@command.to_sym]
  if direction
    "jump #{direction}"
  else
    @command
  end
end