Class: CommandKit::Printing::Tables::TableBuilder Private
- Inherits:
-
Object
- Object
- CommandKit::Printing::Tables::TableBuilder
- Includes:
- Enumerable
- Defined in:
- lib/command_kit/printing/tables/table_builder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Builds a table and calculates it's dimensions.
Instance Attribute Summary collapse
-
#column_widths ⇒ Array<Integer>
readonly
private
The widths of the columns in the table.
-
#header ⇒ Boolean
readonly
private
Indicates whether the table has a header row.
-
#height ⇒ Integer
readonly
private
The height (in lines) of the table.
-
#max_columns ⇒ Integer
readonly
private
The maximum number of columns in the table.
-
#max_rows ⇒ Integer
readonly
private
The maximum number of rows in the table.
-
#rows ⇒ Array<RowBuilder>
readonly
private
The rows within the table.
-
#width ⇒ Integer
readonly
private
The width (in characters) of the table.
Instance Method Summary collapse
-
#<<(row) ⇒ self
private
Appends a row to the table.
-
#[](row_index) ⇒ RowBuilder?
private
Fetches a row from the table.
-
#each {|row| ... } ⇒ Enumerator
private
Enumerates over each row in the table.
-
#header? ⇒ Boolean
private
Determines whether the table has a header row.
-
#initialize(rows = [], header: nil) ⇒ TableBuilder
constructor
private
Initializes the table.
Constructor Details
#initialize(rows = [], header: nil) ⇒ TableBuilder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the table.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 61 def initialize(rows=[], header: nil) @rows = [] @height = 0 @width = 0 @column_widths = [] @max_rows = 0 @max_columns = 0 @header = !header.nil? self << header if header rows.each { |row| self << row } end |
Instance Attribute Details
#column_widths ⇒ Array<Integer> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The widths of the columns in the table.
50 51 52 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 50 def column_widths @column_widths end |
#header ⇒ Boolean (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether the table has a header row.
25 26 27 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 25 def header @header end |
#height ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The height (in lines) of the table.
30 31 32 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 30 def height @height end |
#max_columns ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The maximum number of columns in the table.
45 46 47 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 45 def max_columns @max_columns end |
#max_rows ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The maximum number of rows in the table.
40 41 42 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 40 def max_rows @max_rows end |
#rows ⇒ Array<RowBuilder> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The rows within the table.
20 21 22 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 20 def rows @rows end |
#width ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The width (in characters) of the table.
35 36 37 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 35 def width @width end |
Instance Method Details
#<<(row) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Appends a row to the table.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 94 def <<(row) new_row = RowBuilder.new(row) new_row.each_with_index do |cell,index| column_width = @column_widths[index] || 0 if cell.width > column_width @column_widths[index] = cell.width end end @height += new_row.height @width = new_row.width if new_row.width > @width @max_rows += 1 @max_columns = new_row.columns if new_row.columns > @max_columns @rows << new_row return self end |
#[](row_index) ⇒ RowBuilder?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetches a row from the table.
124 125 126 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 124 def [](row_index) @rows[row_index] end |
#each {|row| ... } ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Enumerates over each row in the table.
140 141 142 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 140 def each(&block) @rows.each(&block) end |
#header? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines whether the table has a header row.
82 83 84 |
# File 'lib/command_kit/printing/tables/table_builder.rb', line 82 def header? @header end |