Class: Toybot::Tabletop

Inherits:
Object
  • Object
show all
Defined in:
lib/toybot/tabletop.rb

Constant Summary collapse

DEFAULT_TABLETOP_WIDTH =

Default values for tabletop x & y +1.0/0.0 => Infinity

+1.0/0.0
DEFAULT_TABLETOP_HEIGHT =
+1.0/0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: DEFAULT_TABLETOP_WIDTH, height: DEFAULT_TABLETOP_HEIGHT) ⇒ Tabletop

A Tabletop has a width and height (Infinity by default). A Tabletop has a minimum size of 1 by 1.



11
12
13
14
15
# File 'lib/toybot/tabletop.rb', line 11

def initialize width: DEFAULT_TABLETOP_WIDTH, height: DEFAULT_TABLETOP_HEIGHT
  @width = width > 0 ? width : 1
  @height = height > 0 ? height : 1
  self.report
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



2
3
4
# File 'lib/toybot/tabletop.rb', line 2

def height
  @height
end

#widthObject

Returns the value of attribute width.



2
3
4
# File 'lib/toybot/tabletop.rb', line 2

def width
  @width
end

Instance Method Details

#reportObject



21
22
23
# File 'lib/toybot/tabletop.rb', line 21

def report
  puts "New tabletop (width: #{@width}, height: #{@height})"
end

#sizeObject



17
18
19
# File 'lib/toybot/tabletop.rb', line 17

def size
  {width: self.width, height: self.height}
end