Class: RbYAML::Stream

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/rbyaml/stream.rb

Overview

RbYAML::Stream – for emitting many documents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Stream

Returns a new instance of Stream.



9
10
11
12
# File 'lib/rbyaml/stream.rb', line 9

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

Instance Attribute Details

#documentsObject

Returns the value of attribute documents.



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

def documents
  @documents
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#[](i) ⇒ Object



14
15
16
# File 'lib/rbyaml/stream.rb', line 14

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

#add(doc) ⇒ Object



18
19
20
# File 'lib/rbyaml/stream.rb', line 18

def add(doc)
  @documents << doc
end

#each(&block) ⇒ Object



26
27
28
# File 'lib/rbyaml/stream.rb', line 26

def each(&block)
  @documents.each(&block)
end

#edit(doc_num, doc) ⇒ Object



22
23
24
# File 'lib/rbyaml/stream.rb', line 22

def edit(doc_num,doc)
  @documents[ doc_num ] = doc
end

#emitObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rbyaml/stream.rb', line 30

def emit
# TODO: implement

  opts = @options.dup
  opts[:UseHeader] = true if @documents.length > 1
  ct = 0
  out = Emitter.new( opts )
  @documents.each { |v|
    if ct > 0
      out << "\n--- " 
    end
    v.to_yaml( :Emitter => out )
    ct += 1
  }
  out.end_object
end