Class: RbYAML::Stream
Overview
RbYAML::Stream – for emitting many documents
Instance Attribute Summary collapse
-
#documents ⇒ Object
Returns the value of attribute documents.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #add(doc) ⇒ Object
- #each(&block) ⇒ Object
- #edit(doc_num, doc) ⇒ Object
- #emit ⇒ Object
-
#initialize(opts = {}) ⇒ Stream
constructor
A new instance of Stream.
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
#documents ⇒ Object
Returns the value of attribute documents.
171 172 173 |
# File 'lib/rbyaml.rb', line 171 def documents @documents end |
#options ⇒ Object
Returns the value of attribute options.
171 172 173 |
# File 'lib/rbyaml.rb', line 171 def @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 |
#emit ⇒ Object
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 |