Class: Robot::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/robot/matrix.rb

Constant Summary collapse

DIRECTION_ARROWS =
{
  north: '^',
  east: '>',
  south: 'v',
  west: '<'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, direction) ⇒ Matrix

Returns a new instance of Matrix.



13
14
15
16
17
# File 'lib/robot/matrix.rb', line 13

def initialize(position, direction)
  @position = position
  @direction = direction
  @matrix = generate_matrix
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



3
4
5
# File 'lib/robot/matrix.rb', line 3

def direction
  @direction
end

#matrixObject

Returns the value of attribute matrix.



4
5
6
# File 'lib/robot/matrix.rb', line 4

def matrix
  @matrix
end

#positionObject (readonly)

Returns the value of attribute position.



3
4
5
# File 'lib/robot/matrix.rb', line 3

def position
  @position
end

Instance Method Details

#to_sObject

puts an arrow pointing in the direction of the current x,y of the robot on a matrix and returns a string of the matrix



22
23
24
25
# File 'lib/robot/matrix.rb', line 22

def to_s
  set_current_position!
  matrix.reverse.map { |row| row.join(' ') }.join("\n")
end