YAML::Emitter (Class)

In: yaml/emitter.rb
Parent: Object

Emit a set of values

Methods

<<   clear   end_object   header   level   new   start_object   version_s  

Attributes

options  [RW] 

Included Modules

BaseEmitter

Public Class methods

[Source]

# File yaml/emitter.rb, line 20
                def initialize( opts )
                        opts = {} if opts.class != Hash
                        @options = YAML::DEFAULTS.dup.update( opts )
            @headless = 0
            @seq_map = false
            @anchors = {}
            @anchor_extras = {}
            @active_anchors = []
            @level = -1
            self.clear
                end

Public Instance methods

Concatenate to the buffer

[Source]

# File yaml/emitter.rb, line 61
                def <<( str )
            #p [ self.id, @level, str ]

                        @buffer.last << str
                end

[Source]

# File yaml/emitter.rb, line 32
                def clear
                        @buffer = []
                end

Output method

[Source]

# File yaml/emitter.rb, line 96
                def end_object
                    @level -= 1
            @buffer.push( "" )
            #p [ self.id, @level, :END ]

                        if @level < 0
                                header + @buffer.to_s[@headless..-1].to_s
                        end
                end

Header

[Source]

# File yaml/emitter.rb, line 50
                def header
            if @headless.nonzero?
                ""
            else
                "---#{version_s} "
            end
                end

[Source]

# File yaml/emitter.rb, line 36
        def level
            @level
        end

Monitor objects and allow references

[Source]

# File yaml/emitter.rb, line 69
        def start_object( oid )
                    @level += 1
            @buffer.push( "" )
            #p [ self.id, @level, :OPEN ]

            idx = nil
            if oid
                if @anchors.has_key?( oid )
                    idx = @active_anchors.index( oid )
                    unless idx
                        idx = @active_anchors.length
                        af_str = "&#{@options[:AnchorFormat]} " % [ idx + 1 ]
                        af_str += @anchor_extras[ @anchors[ oid ] ].to_s
                        @buffer[ @anchors[ oid ] ][0,0] = af_str
                                            @headless = 0 if @anchors[ oid ].zero?
                    end
                    idx += 1
                    @active_anchors.push( oid )
                else
                    @anchors[ oid ] = @buffer.length - 1
                end
            end
            return idx
        end

Version string

[Source]

# File yaml/emitter.rb, line 43
                def version_s
                        " %YAML:#{@options[:Version]}" if @options[:UseVersion]
                end

[Validate]