* transcode.c (transcode_restartable): my_transcoder argument removed.
[ruby-svn.git] / lib / yaml / stream.rb
blob060fbc4200fed12810c119284e02d7babf1317ae
1 module YAML
3         #
4         # YAML::Stream -- for emitting many documents
5         #
6         class Stream
8                 attr_accessor :documents, :options
10                 def initialize( opts = {} )
11                         @options = opts
12                         @documents = []
13                 end
14                 
15         def []( i )
16             @documents[ i ]
17         end
19                 def add( doc )
20                         @documents << doc
21                 end
23                 def edit( doc_num, doc )
24                         @documents[ doc_num ] = doc
25                 end
27                 def emit( io = nil )
28             # opts = @options.dup
29                         # opts[:UseHeader] = true if @documents.length > 1
30             out = YAML.emitter
31             out.reset( io || io2 = StringIO.new )
32             @documents.each { |v|
33                 v.to_yaml( out )
34             }
35             io || ( io2.rewind; io2.read )
36                 end
38         end
40 end