Class: Robot::Table
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#position ⇒ Object
Returns the value of attribute position.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #place(x, y) ⇒ Object
- #placed? ⇒ Boolean
- #valid_position?(position) ⇒ Boolean
Constructor Details
#initialize ⇒ Table
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
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/robot/table.rb', line 8 def height @height end |
#position ⇒ Object
Returns the value of attribute position.
7 8 9 |
# File 'lib/robot/table.rb', line 7 def position @position end |
#width ⇒ Object (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
20 21 22 |
# File 'lib/robot/table.rb', line 20 def placed? !position.nil? end |
#valid_position?(position) ⇒ 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 |