Module: YAML::BaseEmitter

Module | YAML::BaseEmitter
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

binary_base64( value )

Emit binary data

[Source]

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

double( value )

Emit double-quoted string

[Source]

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

fold( value )

Folding paragraphs within a column

[Source]

    # File yaml/baseemitter.rb, line 134
                    def fold( value )
                value.gsub( /(^[ \t]+.*$)|(\S.{0,#{options(:BestWidth) - 1}})(?:[ \t]+|(\n+(?=[ \t]|\Z))|$)/ ) do |s|
                    $1 || $2 + ( $3 || "\n" )
                end
                    end

indent( mod = nil )

Write a current indent

[Source]

    # File yaml/baseemitter.rb, line 113
            def indent( mod = nil )
                #p [ self.id, level, mod, :INDENT ]
                if level <= 0
                    mod ||= 0
                else
                    mod ||= options(:Indent)
                    mod += ( level - 1 ) * options(:Indent)
                end
                return " " * mod
                    end

indent!()

Add indent to the buffer

[Source]

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

indent_text( text, mod, first_line = true )

Write a text block with the current indent

[Source]

    # File yaml/baseemitter.rb, line 103
                    def indent_text( text, mod, first_line = true )
                            return "" if text.to_s.empty?
                spacing = indent( mod )
                text = text.gsub( /\A([^\n])/, "#{ spacing }\\1" ) if first_line
                            return text.gsub( /\n^([^\n])/, "\n#{spacing}\\1" )
                    end

map( type, &e )

Quick mapping

[Source]

    # File yaml/baseemitter.rb, line 143
            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

node_text( value, block = nil )

Emit plain, normal flowing text

[Source]

    # File yaml/baseemitter.rb, line 36
                    def node_text( value, block = nil )
                @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

                    indt = $&.to_i if block =~ /\d+/
                    if valx =~ /(\A\n*[ \t#]|^---\s+)/
                        indt = options(:Indent) unless indt.to_i > 0
                        block += indt.to_s
                    end

                block +=
                    if valx =~ /\n\Z\n/
                        "+"
                    elsif valx =~ /\Z\n/
                        ""
                    else
                        "-"
                    end
                end
                block += "\n"
                if block[0] == ?"
                    esc_skip = ( "\t\n" unless valx =~ /^[ \t]/ ) || ""
                    valx = fold( YAML::escape( valx, esc_skip ) + "\"" ).chomp
                    self << '"' + indent_text( valx, indt, false )
                else
                    if block[0] == ?>
                        valx = fold( valx )
                    end
                    #p [block, indt]
                    self << block + indent_text( valx, indt )
                end
                    end

options( opt = nil )

[Source]

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

options=( opt )

[Source]

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

seq( type, &e )

Quick sequence

[Source]

    # File yaml/baseemitter.rb, line 200
            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

seq_map_shortcut()

[Source]

    # File yaml/baseemitter.rb, line 186
            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

simple( value )

Emit a simple, unqouted string

[Source]

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

single( value )

Emit single-quoted string

[Source]

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

[Validate]