Class: FormatOutput::ColumnBuilder
- Defined in:
- lib/format_output/builders/column_builder.rb
Overview
A class to build columns for display.
Instance Method Summary collapse
-
#add(raw_item) ⇒ Object
Add an item to this page.
-
#initialize(options) ⇒ ColumnBuilder
constructor
Prepare a blank page.
-
#render ⇒ Object
Render the page as an array of strings.
Constructor Details
#initialize(options) ⇒ ColumnBuilder
Prepare a blank page.
10 11 12 13 14 |
# File 'lib/format_output/builders/column_builder.rb', line 10 def initialize() @body = ::FormatOutput.body() @pad = ::FormatOutput.pad() @page_data = [] end |
Instance Method Details
#add(raw_item) ⇒ Object
Add an item to this page. Returns: The number of items that did not fit in the page.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/format_output/builders/column_builder.rb', line 18 def add(raw_item) item = raw_item.to_s fail "Item too large to fit." unless item.length < @body 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.
32 33 34 35 36 37 38 39 |
# File 'lib/format_output/builders/column_builder.rb', line 32 def render results, column_widths = [], get_column_widths rows.times { |row_index| results << render_row(row_index, column_widths)} @page_data.clear results end |