Class: CommandKit::Printing::Tables::CellBuilder Private
- Inherits:
-
Object
- Object
- CommandKit::Printing::Tables::CellBuilder
- Defined in:
- lib/command_kit/printing/tables/cell_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.
Build's a cell and calculates it's dimensions.
Instance Attribute Summary collapse
-
#height ⇒ Integer
readonly
private
The height (in lines) of the cell.
-
#lines ⇒ Array<String>
readonly
private
The lines within the cell.
-
#width ⇒ Integer
readonly
private
The with (in characters) of the cell.
Class Method Summary collapse
-
.line_width(string) ⇒ Integer
private
Calculates the width of a string, sans any ASNI escape sequences.
Instance Method Summary collapse
-
#<<(line) ⇒ self
private
Adds a line to the cell.
-
#[](line_index) ⇒ String
private
Fetches a line from the cell.
-
#initialize(value = nil) ⇒ CellBuilder
constructor
private
Initializes the cell.
Constructor Details
#initialize(value = nil) ⇒ 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.
Initializes the cell.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 34 def initialize(value=nil) @lines = [] @height = 0 @width = 0 if value value.to_s.each_line(chomp: true) do |line| self << line end end end |
Instance Attribute Details
#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 cell.
21 22 23 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 21 def height @height end |
#lines ⇒ Array<String> (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 lines within the cell.
16 17 18 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 16 def lines @lines 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 with (in characters) of the cell.
26 27 28 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 26 def width @width end |
Class Method Details
.line_width(string) ⇒ Integer
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.
Calculates the width of a string, sans any ASNI escape sequences.
55 56 57 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 55 def self.line_width(string) string.gsub(/\e\[\d+m/,'').length end |
Instance Method Details
#<<(line) ⇒ 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.
Adds a line to the cell.
67 68 69 70 71 72 73 74 75 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 67 def <<(line) line_width = self.class.line_width(line) @height += 1 @width = line_width if line_width > @width @lines << line return self end |
#[](line_index) ⇒ String
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 line from the cell.
86 87 88 |
# File 'lib/command_kit/printing/tables/cell_builder.rb', line 86 def [](line_index) @lines.fetch(line_index,'') end |