Class: RbYAML::Stream

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/rbyaml.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.



172
173
174
175
# File 'lib/rbyaml.rb', line 172

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

Instance Attribute Details

#documentsObject

Returns the value of attribute documents.



171
172
173
# File 'lib/rbyaml.rb', line 171

def documents
  @documents
end

#optionsObject

Returns the value of attribute options.



171
172
173
# File 'lib/rbyaml.rb', line 171

def options
  @options
end

Instance Method Details

#[](i) ⇒ Object



177
178
179
# File 'lib/rbyaml.rb', line 177

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

#add(doc) ⇒ Object



181
182
183
# File 'lib/rbyaml.rb', line 181

def add(doc)
  @documents << doc
end

#each(&block) ⇒ Object



189
190
191
# File 'lib/rbyaml.rb', line 189

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

#edit(doc_num, doc) ⇒ Object



185
186
187
# File 'lib/rbyaml.rb', line 185

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

#emitObject



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rbyaml.rb', line 193

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