PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/Ruby/lib/ruby/1.8/yaml/stream.rb

http://github.com/agross/netopenspace
Ruby | 40 lines | 26 code | 9 blank | 5 comment | 2 complexity | b6d3d0f864fad9febc2aed70284fbe27 MD5 | raw file
 1module YAML
 2
 3	#
 4	# YAML::Stream -- for emitting many documents
 5	#
 6	class Stream
 7
 8		attr_accessor :documents, :options
 9
10		def initialize( opts = {} )
11			@options = opts
12			@documents = []
13		end
14		
15        def []( i )
16            @documents[ i ]
17        end
18
19		def add( doc )
20			@documents << doc
21		end
22
23		def edit( doc_num, doc )
24			@documents[ doc_num ] = doc
25		end
26
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
37
38	end
39
40end