Class: XfOOrth::ColumnizedPage

Inherits:
Object
  • Object
show all
Defined in:
lib/fOOrth/library/formatting/columns.rb

Overview

A class to display data in columns.

Instance Method Summary collapse

Constructor Details

#initialize(page_length, page_width) ⇒ ColumnizedPage

Prepare a blank page.



9
10
11
12
# File 'lib/fOOrth/library/formatting/columns.rb', line 9

def initialize(page_length, page_width)
  @page_length, @page_width = page_length, 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/fOOrth/library/formatting/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

#renderObject

Render the page as an array of strings.



31
32
33
34
35
36
37
38
# File 'lib/fOOrth/library/formatting/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