Sha256: 8d8fe303f05fab250a0135612fa9f3902262bc071f434e327cc3b06cff3ec577

Contents?: true

Size: 416 Bytes

Versions: 3

Compression:

Stored size: 416 Bytes

Contents

module Cl
  class Format
    class Table < Struct.new(:data, :separator)
      def format
        rows.join("\n")
      end

      def rows
        rows = data.map { |lft, rgt| [lft.ljust(width), rgt] }
        rows = rows.map { |lft, rgt| "#{lft} #{"# #{rgt}" if rgt}".strip }
        rows.map(&:strip)
      end

      def width
        @width ||= data.map(&:first).max_by(&:size).size
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cl-0.0.4 lib/cl/format/table.rb
cl-0.0.3 lib/cl/format/table.rb
cl-0.0.2 lib/cl/format/table.rb