Sha256: 8aa46673d024359c6840ed497c8e9fbdd63df99f385771e353c8539e033cedfd

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 KB

Contents

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

      attr_reader :hash, :opts

      public

      # Create
      #
      # @param [Hash] hash
      #   Input
      def initialize(hash, opts)
        @hash = hash
        @opts = {
          :sort => true
        }.merge opts
      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
        else
          rows = hash.each_with_object([]) do |(k,v), a|
            a << format("# %-#{name_size}s => %s", k, v)
          end
        end

        if opts[:sort] == true
          rows.sort.join("\n")
        else
          rows.join("\n")
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/platforms/simple_table.rb
aruba-0.14.13 lib/aruba/platforms/simple_table.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/platforms/simple_table.rb
aruba-0.14.12 lib/aruba/platforms/simple_table.rb
aruba-0.14.11 lib/aruba/platforms/simple_table.rb
aruba-0.14.10 lib/aruba/platforms/simple_table.rb
aruba-0.14.9 lib/aruba/platforms/simple_table.rb
aruba-0.14.8 lib/aruba/platforms/simple_table.rb
aruba-0.14.7 lib/aruba/platforms/simple_table.rb
aruba-0.14.6 lib/aruba/platforms/simple_table.rb
aruba-0.14.5 lib/aruba/platforms/simple_table.rb
aruba-0.14.4 lib/aruba/platforms/simple_table.rb
aruba-0.14.3 lib/aruba/platforms/simple_table.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/platforms/simple_table.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/platforms/simple_table.rb
aruba-win-fix-0.14.2 lib/aruba/platforms/simple_table.rb
aruba-0.14.2 lib/aruba/platforms/simple_table.rb
aruba-0.14.1 lib/aruba/platforms/simple_table.rb
aruba-0.14.0 lib/aruba/platforms/simple_table.rb