Class: Alf::Renderer::YAML

Inherits:
Alf::Renderer show all
Defined in:
lib/alf/renderer/yaml.rb

Overview

Implements Alf::Renderer contract for outputing YAML files.

Constant Summary

Constants inherited from Alf::Renderer

DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Alf::Renderer

#input, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Alf::Renderer

by_mime_type, #initialize, register, renderer

Methods included from Support::Registry

#listen, #listeners, #register, #registered

Constructor Details

This class inherits a constructor from Alf::Renderer

Class Method Details

.mime_typeObject



8
9
10
# File 'lib/alf/renderer/yaml.rb', line 8

def self.mime_type
  "text/yaml"
end

Instance Method Details

#each {|"---\n"| ... } ⇒ Object

Yields:

  • ("---\n")


19
20
21
22
23
24
25
26
27
# File 'lib/alf/renderer/yaml.rb', line 19

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

#execute(output = $stdout) ⇒ Object



12
13
14
15
16
17
# File 'lib/alf/renderer/yaml.rb', line 12

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