Class: Robot::Table

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/robot/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



10
11
12
13
# File 'lib/robot/table.rb', line 10

def initialize
  @width = 4
  @height = 4
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/robot/table.rb', line 8

def height
  @height
end

#positionObject

Returns the value of attribute position.



7
8
9
# File 'lib/robot/table.rb', line 7

def position
  @position
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/robot/table.rb', line 8

def width
  @width
end

Instance Method Details

#place(x, y) ⇒ Object



15
16
17
18
# File 'lib/robot/table.rb', line 15

def place(x, y)
  position = { x: x.to_i, y: y.to_i }
  self.position = position if valid_position?(position)
end

#placed?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/robot/table.rb', line 20

def placed?
  !position.nil?
end

#valid_position?(position) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/robot/table.rb', line 24

def valid_position?(position)
  position[:x] <= width && position[:x] >= 0 && \
    position[:y] <= height && position[:y] >= 0
end