Class: CommandKit::Printing::Tables::RowBuilder Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/command_kit/printing/tables/row_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 row and calculates it's dimensions.

Since:

  • 0.4.0

Constant Summary collapse

EMPTY_CELL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

An empty cell.

Since:

  • 0.4.0

CellBuilder.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cells = nil) ⇒ 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.

Initializes the row.

Parameters:

  • cells (Array, nil) (defaults to: nil)

    The cells for the row.

Since:

  • 0.4.0



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/command_kit/printing/tables/row_builder.rb', line 43

def initialize(cells=nil)
  @cells = []

  @height = 0
  @width  = 0

  @columns = 0

  if cells
    cells.each { |value| self << value }
  end
end

Instance Attribute Details

#cellsArray<CellBuilder> (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 cells within the row.

Returns:

Since:

  • 0.4.0



20
21
22
# File 'lib/command_kit/printing/tables/row_builder.rb', line 20

def cells
  @cells
end

#columnsInteger (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 number of columns in the row.

Returns:

  • (Integer)

Since:

  • 0.4.0



35
36
37
# File 'lib/command_kit/printing/tables/row_builder.rb', line 35

def columns
  @columns
end

#heightInteger (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) for the row.

Returns:

  • (Integer)

Since:

  • 0.4.0



25
26
27
# File 'lib/command_kit/printing/tables/row_builder.rb', line 25

def height
  @height
end

#widthInteger (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) for the row.

Returns:

  • (Integer)

Since:

  • 0.4.0



30
31
32
# File 'lib/command_kit/printing/tables/row_builder.rb', line 30

def width
  @width
end

Instance Method Details

#<<(value) ⇒ 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 value to the row.

Parameters:

  • value (#to_s)

    The cell value to add to the row.

Returns:

  • (self)

Since:

  • 0.4.0



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/command_kit/printing/tables/row_builder.rb', line 67

def <<(value)
  new_cell = if value then CellBuilder.new(value)
             else          EMPTY_CELL
             end

  @height   = new_cell.height if new_cell.height > @height
  @width   += new_cell.width
  @columns += 1

  @cells << new_cell
  return self
end

#[](column_index) ⇒ CellBuilder

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 cell from the row.

Parameters:

  • column_index (Integer)

    The column index.

Returns:

  • (CellBuilder)

    The cell at the given column index or an empty cell if the row does not have a cell at the given column index.

Since:

  • 0.4.0



90
91
92
# File 'lib/command_kit/printing/tables/row_builder.rb', line 90

def [](column_index)
  @cells.fetch(column_index,EMPTY_CELL)
end

#each {|cell| ... } ⇒ 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 cell in the row.

Yields:

  • (cell)

    The given block will be passed each cell within the row.

Yield Parameters:

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.

Since:

  • 0.4.0



106
107
108
# File 'lib/command_kit/printing/tables/row_builder.rb', line 106

def each(&block)
  @cells.each(&block)
end