Class: Alf::Renderer::Text::Row

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/alf/renderer/text.rb

Overview

class Cell

Instance Method Summary collapse

Methods included from Utils

#max

Constructor Details

#initialize(values, options = {}) ⇒ Row

Returns a new instance of Row


84
85
86
87
# File 'lib/alf/renderer/text.rb', line 84

def initialize(values, options = {})
  @cells = values.map{|v| Cell.new(v, options)}
  @options = options
end

Instance Method Details

#min_widthsObject


89
90
91
# File 'lib/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/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