Sha256: 62cee1f6c7d01bf9075638294ecb0f6864e237668de71c22633c224796e87834

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

module Gerrit
  module Cli
  end
end

module Gerrit::Cli::Util
  class << self
    def render_table(rows, opts={})
      return "" if rows.empty?

      max_col_lengths = []
      rows.first.length.times { max_col_lengths << 0 }

      # Compute maximum length of each column
      rows.each do |row|
        if row.length != max_col_lengths.length
          raise ArgumentError, "Column mismatch"
        end

        row.each_with_index do |c, ii|
          len = c.to_s.length
          if len> max_col_lengths[ii]
            max_col_lengths[ii] = len
          end
        end
      end

      delim = opts[:delimiter] || ' '
      row_format = max_col_lengths.map {|len| "%-#{len}s" }.join(delim)

      rows.map {|row| row_format % row }.join("\n")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gerrit-cli-0.0.1 lib/gerrit/cli/util.rb