Class: MakeMenu::Text::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/make_menu/text/table.rb

Overview

This class displays the menu groups in columns across the screen. Each group is kept together in a column, and once a column has exceeded the calculated height, a new column is added.

Constant Summary collapse

MAX_COLUMNS =
4

Instance Method Summary collapse

Constructor Details

#initialize(groups) ⇒ Table

Returns a new instance of Table.

Parameters:



14
15
16
17
18
19
# File 'lib/make_menu/text/table.rb', line 14

def initialize(groups)
  @groups = groups
  @columns = []
  calculate_table_dimensions
  build_table
end

Instance Method Details

#to_sString

Returns The entire table, centered on the screen.

Returns:

  • (String)

    The entire table, centered on the screen



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/make_menu/text/table.rb', line 22

def to_s
  buffer = ''

  max_height.times do |i|
    row = ''
    columns.each do |column|
      row += column.row(i) unless column.empty?
    end
    buffer += "#{row.align(:center)}\n"
  end

  buffer
end