/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

  1. module YAML
  2. #
  3. # YAML::Stream -- for emitting many documents
  4. #
  5. class Stream
  6. attr_accessor :documents, :options
  7. def initialize( opts = {} )
  8. @options = opts
  9. @documents = []
  10. end
  11. def []( i )
  12. @documents[ i ]
  13. end
  14. def add( doc )
  15. @documents << doc
  16. end
  17. def edit( doc_num, doc )
  18. @documents[ doc_num ] = doc
  19. end
  20. def emit( io = nil )
  21. # opts = @options.dup
  22. # opts[:UseHeader] = true if @documents.length > 1
  23. out = YAML.emitter
  24. out.reset( io || io2 = StringIO.new )
  25. @documents.each { |v|
  26. v.to_yaml( out )
  27. }
  28. io || ( io2.rewind; io2.read )
  29. end
  30. end
  31. end