Class: MakeMenu::TextTable

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) ⇒ TextTable

Returns a new instance of TextTable.

Parameters:



13
14
15
16
17
18
# File 'lib/make_menu/text_table.rb', line 13

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



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

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