Class: Surface::Table

Inherits:
Object
  • Object
show all
Includes:
TableInterface
Defined in:
lib/surface/table.rb

Overview

TODO:

Add functionality to add Obsturctions on Table

Table class represents a square table of 5x5 by default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rows = 5, columns = 5) ⇒ Table

Returns a new instance of Table.

Parameters:

  • rows (Integer) (defaults to: 5)
  • columns (Integer) (defaults to: 5)


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

def initialize(rows = 5, columns = 5)
  @grid = Array.new(rows) { Array.new(columns) { 0 } }
  @rows = rows
  @columns = columns
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



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

def columns
  @columns
end

#gridObject

Returns the value of attribute grid.



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

def grid
  @grid
end

#rowsObject

Returns the value of attribute rows.



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

def rows
  @rows
end

Instance Method Details

#can_be_placed?(x, y) ⇒ Boolean

validates if the x, y can be placed on to the table

Parameters:

  • x (Integer)
  • y (Integer)

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/surface/table.rb', line 24

def can_be_placed?(x, y)
  return false unless (0..(rows - 1)).include?(x)
  return false unless (0..(columns - 1)).include?(y)

  true
end