Class: Surface::Table
- Inherits:
-
Object
- Object
- Surface::Table
- 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
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
-
#can_be_placed?(x, y) ⇒ Boolean
validates if the x, y can be placed on to the table.
-
#initialize(rows = 5, columns = 5) ⇒ Table
constructor
A new instance of Table.
Constructor Details
#initialize(rows = 5, columns = 5) ⇒ Table
Returns a new instance of Table.
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
#columns ⇒ Object
Returns the value of attribute columns.
10 11 12 |
# File 'lib/surface/table.rb', line 10 def columns @columns end |
#grid ⇒ Object
Returns the value of attribute grid.
10 11 12 |
# File 'lib/surface/table.rb', line 10 def grid @grid end |
#rows ⇒ Object
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
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 |