Class: Mysh::ColumnizedPage
- Defined in:
- lib/mysh/internal/format/columns.rb
Overview
-
mysh/internal/format/columns.rb - A class to display data in columns.
Instance Method Summary collapse
-
#add(raw_item) ⇒ Object
Add an item to this page.
-
#initialize(page_width) ⇒ ColumnizedPage
constructor
Prepare a blank page.
-
#render ⇒ Object
Render the page as an array of strings.
Constructor Details
#initialize(page_width) ⇒ ColumnizedPage
Prepare a blank page.
9 10 11 12 |
# File 'lib/mysh/internal/format/columns.rb', line 9 def initialize(page_width) @page_width = page_width @page_data = [] end |
Instance Method Details
#add(raw_item) ⇒ Object
Add an item to this page.
Returns
-
The number if items that did not fit in the page.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mysh/internal/format/columns.rb', line 17 def add(raw_item) item = raw_item.to_s fail "Item too large to fit." unless item.length < @page_width if (column = find_next_column) @page_data[column] << item else @page_data << [item] end adjust_configuration end |
#render ⇒ Object
Render the page as an array of strings.
31 32 33 34 35 36 37 38 |
# File 'lib/mysh/internal/format/columns.rb', line 31 def render results, column_widths = [], get_column_widths rows.times { |row_index| results << render_row(row_index, column_widths)} @page_data.clear results end |