Sha256: 6a3e7d3f71102f7b302bc3ba27b552c51b9fbbd543a6b1099a8bc5417ff3a007

Contents?: true

Size: 869 Bytes

Versions: 6

Compression:

Stored size: 869 Bytes

Contents

# Aruba
module Aruba
  # Platforms
  module Platforms
    # Generate simple table
    class SimpleTable
      private

      attr_reader :hash

      public

      # Create
      #
      # @param [Hash] hash
      #   Input
      def initialize(hash)
        @hash = hash
      end

      # Generate table
      #
      # @return [String]
      #   The table
      def to_s
        longest_key = hash.keys.map(&:to_s).max_by(&:length)
        return [] if longest_key.nil?

        name_size  = longest_key.length

        if RUBY_VERSION < '2'
          rows = []

          hash.each do |k,v|
            rows << format("# %-#{name_size}s => %s", k, v)
          end

          rows.sort
        else
          hash.each_with_object([]) do |(k,v), a|
            a << format("# %-#{name_size}s => %s", k, v)
          end.sort
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
aruba-0.12.0 lib/aruba/platforms/simple_table.rb
aruba-0.11.2 lib/aruba/platforms/simple_table.rb
aruba-0.11.1 lib/aruba/platforms/simple_table.rb
aruba-0.11.0.pre4 lib/aruba/platforms/simple_table.rb
aruba-0.11.0.pre3 lib/aruba/platforms/simple_table.rb
aruba-0.11.0.pre2 lib/aruba/platforms/simple_table.rb