Class: Text::Table::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/text-table/row.rb

Overview

A Text::Table::Row belongs to a Text::Table object and can have many Text::Table::Cell objects. It handles the rendering of rows and inserted separators.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_input, table) ⇒ Row

:nodoc:


11
12
13
14
15
16
17
# File 'lib/text-table/row.rb', line 11

def initialize(row_input, table) #:nodoc:
  @table = table
  row_input = [row_input].flatten
  @cells = row_input.first == :separator ? :separator : row_input.map do |cell_input|
    Cell.new(cell_input.is_a?(Hash) ? cell_input.merge(:row => self) : {:value => cell_input}.merge(:row => self))
  end
end

Instance Attribute Details

#cellsObject (readonly)

:nodoc:


9
10
11
# File 'lib/text-table/row.rb', line 9

def cells
  @cells
end

#tableObject (readonly)

:nodoc:


8
9
10
# File 'lib/text-table/row.rb', line 8

def table
  @table
end

Instance Method Details

#to_sObject

:nodoc:


19
20
21
22
23
24
25
26
27
# File 'lib/text-table/row.rb', line 19

def to_s #:nodoc:
  if cells == :separator
    table.separator
  else
    ([table.horizontal_boundary] * 2).join(
      cells.map(&:to_s).join(table.horizontal_boundary)
    ) + "\n"
  end
end