72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/dashes.rb', line 72
def to_s
return '' if @rows.empty?
widths = col_widths
format = []
separator = "+-#{widths.map {|w| '-'*w}.join('-+-')}-+"
format << separator
@rows.each_with_index do |row, index|
@separators.select { |s| s == index }.count.times { format << separator }
line = []
row.each_with_index do |data, col|
line << cell(data, widths[col], @aligns[col] || :left)
end
format << "| #{line.join(' | ')} |"
end
@separators.select { |s| s == @rows.length }.count.times { format << separator }
format << separator
format.join("\n")
end
|