Class: Tablecon::TablePrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/tablecon.rb

Instance Method Summary collapse

Constructor Details

#initialize(rows) ⇒ TablePrinter

Returns a new instance of TablePrinter.



24
25
26
27
# File 'lib/tablecon.rb', line 24

def initialize rows
  @rows = rows
  raise "Rows are empty!" if @rows.empty?
end

Instance Method Details

#strObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tablecon.rb', line 29

def str
  ret = ""
  ret << header
  @rows.each do |row|
    row.each do |cell|
      ret << "|"
      ret << cell.value.to_s.center(cell.width + 2)
    end
    ret << "|\n"
    ret << delimiter  
  end
  ret
end