Sha256: 9c4e2f844316394e965291847e18fabe10d2dcf02340759dd11a043b78ce43ec

Contents?: true

Size: 766 Bytes

Versions: 4

Compression:

Stored size: 766 Bytes

Contents

module Alf
  class Renderer
    #
    # Implements Alf::Renderer contract for outputing YAML files.
    #
    class YAML < ::Alf::Renderer

      def self.mime_type
        "text/yaml"
      end

      def execute(output = $stdout)
        require "psych"
        visitor = Psych::Visitors::YAMLTree.new
        visitor << self
        output << visitor.tree.to_yaml
      end

      def each
        return to_enum unless block_given?
        require "yaml"
        yield("---\n")
        Engine::ToArray.new(input).each do |tuple|
          yield "-" << tuple.to_hash.to_yaml[4..-1].gsub(/^/, "  ")[1..-1]
        end
        yield("\n")
      end

      Alf::Renderer.register(:yaml, "in YAML",  self)
    end # class YAML
  end # class Renderer
end # module Alf

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/renderer/yaml.rb
alf-core-0.16.2 lib/alf/renderer/yaml.rb
alf-core-0.16.1 lib/alf/renderer/yaml.rb
alf-core-0.16.0 lib/alf/renderer/yaml.rb