Sha256: 10d31b8ebc22123229a184e882d300a281b82e05881fcba576c0ae1ae4128227

Contents?: true

Size: 779 Bytes

Versions: 8

Compression:

Stored size: 779 Bytes

Contents

module Alf
  class Renderer
    #
    # Implements the Renderer contract through inspect
    #
    class Rash < Renderer

      def self.mime_type
        nil
      end

      def each
        return to_enum unless block_given?
        if options[:pretty]
          each_tuple do |tuple|
            yield "{\n" << tuple.map{|k,v| "  #{l(k)} => #{l(v)}"}.join(",\n") << "\n}\n"
          end
        else
          each_tuple do |tuple|
            yield to_rash(tuple) << "\n"
          end
        end
      end

    private

      def l(x)
        Support.to_ruby_literal(x)
      end

      def to_rash(x)
        l(x.is_a?(Tuple) ? x.to_hash : x)
      end

      Renderer.register(:rash, "as ruby hashes", self)
    end # class Rash
  end # class Renderer
end # module Alf

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/renderer/rash.rb
alf-core-0.16.2 lib/alf/renderer/rash.rb
alf-core-0.16.1 lib/alf/renderer/rash.rb
alf-core-0.16.0 lib/alf/renderer/rash.rb
alf-core-0.15.0 lib/alf/renderer/rash.rb
alf-core-0.14.0 lib/alf-io/alf/renderer/rash.rb
alf-core-0.13.1 lib/alf-io/alf/renderer/rash.rb
alf-core-0.13.0 lib/alf-io/alf/renderer/rash.rb