Class: Syck::Stream

Inherits:
Object show all
Defined in:
lib/syck/stream.rb

Overview

YAML::Stream -- for emitting many documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Stream

Returns a new instance of Stream.


10
11
12
13
# File 'lib/syck/stream.rb', line 10

def initialize( opts = {} )
	@options = opts
	@documents = []
end

Instance Attribute Details

#documentsObject

Returns the value of attribute documents


8
9
10
# File 'lib/syck/stream.rb', line 8

def documents
  @documents
end

#optionsObject

Returns the value of attribute options


8
9
10
# File 'lib/syck/stream.rb', line 8

def options
  @options
end

Instance Method Details

#[](i) ⇒ Object


15
16
17
# File 'lib/syck/stream.rb', line 15

def []( i )
    @documents[ i ]
end

#add(doc) ⇒ Object


19
20
21
# File 'lib/syck/stream.rb', line 19

def add( doc )
	@documents << doc
end

#edit(doc_num, doc) ⇒ Object


23
24
25
26
# File 'lib/syck/stream.rb', line 23

def edit( doc_num, doc )
                warn "#{caller[0]}: edit is deprecated" if $VERBOSE
	@documents[ doc_num ] = doc
end

#emit(io = nil) ⇒ Object


28
29
30
31
32
33
34
35
36
37
# File 'lib/syck/stream.rb', line 28

def emit( io = nil )
          # opts = @options.dup
	# opts[:UseHeader] = true if @documents.length > 1
          out = Syck.emitter
          out.reset( io || io2 = StringIO.new )
          @documents.each { |v|
              v.to_yaml( out )
          }
          io || ( io2.rewind; io2.read )
end