Sha256: 43154ba4a8b4777d1f83b39b7cd85439476591cde8817cdc3a74271b45d89d38

Contents?: true

Size: 724 Bytes

Versions: 6

Compression:

Stored size: 724 Bytes

Contents

module Alf
  class Renderer
    #
    # Implements the Renderer contract through inspect
    #
    class Rash < Renderer
  
      # (see Renderer#render)
      def render(input, output)
        if options[:pretty]
          input.each do |tuple|
            output << "{\n" << tuple.collect{|k,v| 
              "  #{lit(k)} => #{lit(v)}" 
            }.join(",\n") << "\n}\n"
          end
        else
          input.each do |tuple|
            output << lit(tuple) << "\n"
          end
        end
        output
      end

      private 

      def lit(x)
        Tools.to_ruby_literal(x)
      end
  
      Renderer.register(:rash, "as ruby hashes", self)
    end # class Rash
  end # class Renderer
end # module Alf

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf/renderer/rash.rb
alf-0.12.1 lib/alf/renderer/rash.rb
alf-0.12.0 lib/alf/renderer/rash.rb
alf-0.11.1 lib/alf/renderer/rash.rb
alf-0.11.0 lib/alf/renderer/rash.rb
alf-0.10.1 lib/alf/renderer/rash.rb