Class: RbYAML::Stream
- Includes:
- Enumerable
- Defined in:
- lib/rbyaml/stream.rb
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.
9 10 11 12 |
# File 'lib/rbyaml/stream.rb', line 9 def initialize(opts = {}) @options = opts @documents = [] end |
Instance Attribute Details
#documents ⇒ Object
Returns the value of attribute documents.
8 9 10 |
# File 'lib/rbyaml/stream.rb', line 8 def documents @documents end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/rbyaml/stream.rb', line 8 def @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 |
#emit ⇒ Object
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 |