Class: Alf::Renderer::Text::Row
- Inherits:
-
Object
- Object
- Alf::Renderer::Text::Row
- Includes:
- Utils
- Defined in:
- lib/alf-io/alf/renderer/text.rb
Overview
class Cell
Instance Method Summary collapse
-
#initialize(values, options = {}) ⇒ Row
constructor
A new instance of Row.
- #min_widths ⇒ Object
- #rendering_lines(sizes = min_widths) ⇒ Object
Methods included from Utils
Constructor Details
#initialize(values, options = {}) ⇒ Row
Returns a new instance of Row.
84 85 86 87 |
# File 'lib/alf-io/alf/renderer/text.rb', line 84 def initialize(values, = {}) @cells = values.map{|v| Cell.new(v, )} = end |
Instance Method Details
#min_widths ⇒ Object
89 90 91 |
# File 'lib/alf-io/alf/renderer/text.rb', line 89 def min_widths @cells.map{|cell| cell.min_width} end |
#rendering_lines(sizes = min_widths) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/alf-io/alf/renderer/text.rb', line 93 def rendering_lines(sizes = min_widths) nb_lines = 0 by_cell = @cells.zip(sizes).map do |cell,size| lines = cell.rendering_lines(size) nb_lines = max(nb_lines, lines.size) lines end grid = (0...nb_lines).map do |line_i| "| " + by_cell.zip(sizes).map{|cell_lines, size| cell_lines[line_i] || " "*size }.join(" | ") + " |" end grid.empty? ? ["| |"] : grid end |