60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/mergetrain_check/formatter.rb', line 60
def to_table
output = ''
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
output += head = '-' * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1) + "\n"
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))}
output += '| ' + row.join(' | ') + ' |' + "\n"
if idx == 0
row = row.each_with_index.map{|v, i| v = '-' * v.to_s.length}
output += '| ' + row.join(' | ') + ' |' + "\n"
end
end
output += head
end
|