1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/yaml/stream.rb
why a1e257ec48 * ext/syck/emitter.c: new emitter code.
* ext/syck/rubyext.c: Emitter class.

* lib/yaml.rb: Load Syck emitter, if available.

* lib/yaml/stream.rb: ditto.

* lib/yaml/baseemitter.rb: underlying class for all emitters.

* lib/yaml/rubytypes.rb: use BaseEmitter abstraction.

* lib/yaml/emitter.rb: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-11 22:52:14 +00:00

44 lines
766 B
Ruby

module YAML
#
# YAML::Stream -- for emitting many documents
#
class Stream
attr_accessor :documents, :options
def initialize( opts = {} )
@options = opts
@documents = []
end
def []( i )
@documents[ i ]
end
def add( doc )
@documents << doc
end
def edit( doc_num, doc )
@documents[ doc_num ] = doc
end
def emit
opts = @options.dup
opts[:UseHeader] = true if @documents.length > 1
ct = 0
out = YAML::Syck::Emitter.new( opts )
@documents.each { |v|
if ct > 0
out << "\n--- "
end
v.to_yaml( :Emitter => out )
ct += 1
}
out.end_object
end
end
end