YAML::BaseEmitter (Module)

In: yaml/baseemitter.rb

Methods

binary_base64   double   fold   indent   indent!   indent_text   map   node_text   options   options=   seq   seq_map_shortcut   simple   single  

Public Instance methods

Emit binary data

[Source]

# File yaml/baseemitter.rb, line 28
        def binary_base64( value )
            self << "!binary "
            self.node_text( [value].pack("m"), '|' )
        end

Emit double-quoted string

[Source]

# File yaml/baseemitter.rb, line 82
                def double( value )
                        "\"#{YAML.escape( value )}\"" 
                end

Folding paragraphs within a column

[Source]

# File yaml/baseemitter.rb, line 120
                def fold( value )
                        value.gsub!( /\A\n+/, '' )
                        folded = $&.to_s
                        width = (0..options(:BestWidth))
                        while not value.empty?
                                last = value.index( /(\n+)/ )
                                chop_s = false
                                if width.include?( last )
                                        last += $1.length - 1
                                elsif width.include?( value.length )
                                        last = value.length
                                else
                                        last = value.rindex( /[ \t]/, options(:BestWidth) )
                                        chop_s = true
                                end
                                folded += value.slice!( 0, width.include?( last ) ? last + 1 : options(:BestWidth) )
                                folded.chop! if chop_s
                                folded += "\n" unless value.empty?
                        end
                        folded
                end

Write a current indent

[Source]

# File yaml/baseemitter.rb, line 105
                def indent
            #p [ self.id, @level, :INDENT ]

                        return " " * ( level * options(:Indent) )
                end

Add indent to the buffer

[Source]

# File yaml/baseemitter.rb, line 113
                def indent!
                        self << indent
                end

Write a text block with the current indent

[Source]

# File yaml/baseemitter.rb, line 96
                def indent_text( text, indt = nil )
                        return "" if text.to_s.empty?
            spacing = " " * ( level * ( indt || options(:Indent) ) )
                        return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
                end

Quick mapping

[Source]

# File yaml/baseemitter.rb, line 145
        def map( type, &e )
            val = Mapping.new
            e.call( val )
                        self << "#{type} " if type.length.nonzero?

                        #

                        # Empty hashes

                        #

                        if val.length.zero?
                                self << "{}"
                @seq_map = false
                        else
                # FIXME

                # if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero? 

                            #     @headless = 1 

                # end


                defkey = @options.delete( :DefaultKey )
                if defkey
                    seq_map_shortcut
                    self << "= : "
                    defkey.to_yaml( :Emitter => self )
                end

                                #

                                # Emit the key and value

                                #

                val.each { |v|
                    seq_map_shortcut
                    if v[0].is_complex_yaml?
                        self << "? "
                    end
                    v[0].to_yaml( :Emitter => self )
                    if v[0].is_complex_yaml?
                        self << "\n"
                        indent!
                    end
                    self << ": " 
                    v[1].to_yaml( :Emitter => self )
                }
                        end
        end

Emit plain, normal flowing text

[Source]

# File yaml/baseemitter.rb, line 36
                def node_text( value, block = '>' )
            @seq_map = false
                        valx = value.dup
            unless block
            block =
                if options(:UseBlock)
                    '|'
                elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
                    '|'
                else
                    '>'
                end 
            block +=
                if valx =~ /\n\Z\n/
                    "+"
                elsif valx =~ /\Z\n/
                    ""
                else
                    "-"
                end
                if valx =~ /\A[ \t#]/
                    block += options(:Indent).to_s
                end
            end
                        if valx =~ /#{YAML::ESCAPE_CHAR}/
                                valx = YAML::escape( valx )
                        end
                        if block[0] == ?> 
                                valx = fold( valx ) 
                        end
            indt = nil
            indt = $&.to_i if block =~ /\d+/
                        self << block + indent_text( valx, indt ) + "\n"
                end

[Source]

# File yaml/baseemitter.rb, line 13
        def options( opt = nil )
            if opt
                @options[opt] || YAML::DEFAULTS[opt]
            else
                @options
            end
        end

[Source]

# File yaml/baseemitter.rb, line 21
        def options=( opt )
            @options = opt
        end

Quick sequence

[Source]

# File yaml/baseemitter.rb, line 202
        def seq( type, &e )
            @seq_map = false
            val = Sequence.new
            e.call( val )
                        self << "#{type} " if type.length.nonzero?

                        #

                        # Empty arrays

                        #

                        if val.length.zero?
                                self << "[]"
                        else
                # FIXME

                # if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero? 

                            #     @headless = 1 

                # end


                                #

                                # Emit the key and value

                                #

                val.each { |v|
                    self << "\n"
                    indent!
                    self << "- "
                    @seq_map = true if v.class == Hash
                    v.to_yaml( :Emitter => self )
                }
                        end
        end

[Source]

# File yaml/baseemitter.rb, line 188
        def seq_map_shortcut
            # FIXME: seq_map needs to work with the new anchoring system

            # if @seq_map

            #     @anchor_extras[@buffer.length - 1] = "\n" + indent

            #     @seq_map = false

            # else

                self << "\n"
                indent! 
            # end

        end

Emit a simple, unqouted string

[Source]

# File yaml/baseemitter.rb, line 74
                def simple( value )
            @seq_map = false
            self << value.to_s
                end

Emit single-quoted string

[Source]

# File yaml/baseemitter.rb, line 89
                def single( value )
                        "'#{value}'"
                end

[Validate]