Sha256: c327ecd9b6265699a6d187d76182a4becf8fffbb09ae2fa4353f67e5a9391b96

Contents?: true

Size: 677 Bytes

Versions: 9

Compression:

Stored size: 677 Bytes

Contents

module Aruba
  module Platforms
    class SimpleTable
      private

      attr_reader :hash

      public

      def initialize(hash)
        @hash = hash
      end

      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

9 entries across 9 versions & 1 rubygems

Version Path
aruba-0.11.0.pre lib/aruba/platforms/simple_table.rb
aruba-0.10.2 lib/aruba/platforms/simple_table.rb
aruba-0.10.1 lib/aruba/platforms/simple_table.rb
aruba-0.10.0 lib/aruba/platforms/simple_table.rb
aruba-0.10.0.pre2 lib/aruba/platforms/simple_table.rb
aruba-0.10.0.pre lib/aruba/platforms/simple_table.rb
aruba-0.9.0 lib/aruba/platforms/simple_table.rb
aruba-0.9.0.pre2 lib/aruba/platforms/simple_table.rb
aruba-0.9.0.pre lib/aruba/platforms/simple_table.rb