module Coverband::Utils::ArrayToTableInConsole
Public Instance Methods
to_table()
click to toggle source
# File lib/coverband/utils/dead_methods.rb, line 9 def to_table column_sizes = reduce([]) { |lengths, row| row.each_with_index.map do |iterand, index| [lengths[index] || 0, iterand.to_s.length].max end } puts head = "-" * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1) each do |row| row = row.fill(nil, row.size..(column_sizes.size - 1)) row = row.each_with_index.map { |v, i| v.to_s + " " * (column_sizes[i] - v.to_s.length) } puts "| " + row.join(" | ") + " |" end puts head end