37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/mergetrain_check/formatter.rb', line 37
def to_table
column_sizes = self.reduce([]) do |lengths, row|
row.each_with_index.map{|iterand, index| [lengths[index] || 0, iterand.to_s.length + count_emojis(iterand.to_s)].max}
end
puts head = '-' * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1)
self.each_with_index do |row, idx|
row = row.fill(nil, row.size..(column_sizes.size - 1))
row = row.each_with_index.map{|v, i| v = v.to_s + ' ' * (column_sizes[i] - v.to_s.length - count_emojis(v.to_s))}
puts '| ' + row.join(' | ') + ' |'
if idx == 0
row = row.each_with_index.map{|v, i| v = '-' * v.to_s.length}
puts '| ' + row.join(' | ') + ' |'
end
end
puts head
end
|