Sha256: cbba9ad237ff5292c4f9eaac16e890f5059f966e7be2dcce86cb2358041ad9f8

Contents?: true

Size: 1.11 KB

Versions: 31

Compression:

Stored size: 1.11 KB

Contents

begin
  require 'awesome_print'
rescue LoadError
end

# Fix the way ap indents hashes:

# for awesome_print <= 0.4.0
class AwesomePrint
# for awesome_print >= 1.0.0
#class AwesomePrint::Formatter
  private

  # Format a hash. If @options[:indent] if negative left align hash keys.
  #------------------------------------------------------------------------------
  def awesome_hash(h)
    return "{}" if h == {}

    keys = @options[:sorted_hash_keys] ? h.keys.sort { |a, b| a.to_s <=> b.to_s } : h.keys
    data = keys.map do |key|
      plain_single_line do
        #[ @inspector.awesome(key), h[key] ]
        [ awesome(key), h[key] ]
      end
    end
      
    data = data.map do |key, value|
      if @options[:multiline]
        formatted_key = indent + key
      else
        formatted_key = key
      end
      indented do
        #formatted_key << colorize(" => ", :hash) << @inspector.awesome(value)
        formatted_key << colorize(" => ", :hash) << awesome(value)
      end
    end
    if @options[:multiline]
      "{\n" << data.join(",\n") << "\n#{outdent}}"
    else
      "{ #{data.join(', ')} }"
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
pacer-2.0.24-java lib/pacer/support/awesome_print.rb
pacer-2.0.22-java lib/pacer/support/awesome_print.rb
pacer-2.0.20-java lib/pacer/support/awesome_print.rb
pacer-2.0.19-java lib/pacer/support/awesome_print.rb
pacer-2.0.18-java lib/pacer/support/awesome_print.rb
pacer-2.0.17-java lib/pacer/support/awesome_print.rb
pacer-2.0.16-java lib/pacer/support/awesome_print.rb
pacer-2.0.15-java lib/pacer/support/awesome_print.rb
pacer-2.0.14-java lib/pacer/support/awesome_print.rb
pacer-2.0.13-java lib/pacer/support/awesome_print.rb
pacer-2.0.12-java lib/pacer/support/awesome_print.rb
pacer-2.0.10-java lib/pacer/support/awesome_print.rb
pacer-2.0.10.pre-java lib/pacer/support/awesome_print.rb
pacer-2.0.8-java lib/pacer/support/awesome_print.rb
pacer-2.0.6-java lib/pacer/support/awesome_print.rb
pacer-2.0.4.pre-java lib/pacer/support/awesome_print.rb
pacer-2.0.0.pre-java lib/pacer/support/awesome_print.rb
pacer-1.6.0-java lib/pacer/support/awesome_print.rb
pacer-1.5.4-java lib/pacer/support/awesome_print.rb
pacer-1.5.3-java lib/pacer/support/awesome_print.rb