class YAML::Nodes::Builder
inherits Reference
¶
Builds a tree of YAML nodes.
This builder is similar to YAML::Builder
, but instead of
directly emitting the output to an IO it builds a YAML document
tree in memory.
All "emitting" methods support specifying a "reference" object that will be associated to the emitted object, so that when that reference object is emitted again an anchor and an alias will be created. This generates both more compact documents and allows handling recursive data structures.
Class methods¶
Methods¶
#alias(anchor : String) : Nil
¶
(anchor : String) : Nil
Emits an alias to the given anchor.
require "yaml"
nodes_builder = YAML::Nodes::Builder.new
nodes_builder.mapping do
nodes_builder.scalar "foo"
nodes_builder.alias "key"
end
yaml = YAML.build do |builder|
nodes_builder.document.to_yaml builder
end
yaml # => "---\nfoo: *key\n"
#mapping(anchor : String? = nil, tag : String? = nil, style : YAML::MappingStyle = YAML::MappingStyle::ANY, reference = nil, &) : Nil
¶
(anchor : String? = nil, tag : String? = nil, style : YAML::MappingStyle = YAML::MappingStyle::ANY, reference = nil, &) : Nil
#merge(anchor : String) : Nil
¶
(anchor : String) : Nil
Emits the scalar "<<"
followed by an alias to the given anchor.
See YAML Merge.
require "yaml"
nodes_builder = YAML::Nodes::Builder.new
nodes_builder.mapping do
nodes_builder.merge "key"
end
yaml = YAML.build do |builder|
nodes_builder.document.to_yaml builder
end
yaml # => "---\n<<: *key\n"
#scalar(value, anchor : String? = nil, tag : String? = nil, style : YAML::ScalarStyle = YAML::ScalarStyle::ANY, reference = nil) : Nil
¶
(value, anchor : String? = nil, tag : String? = nil, style : YAML::ScalarStyle = YAML::ScalarStyle::ANY, reference = nil) : Nil
#sequence(anchor : String? = nil, tag : String? = nil, style : YAML::SequenceStyle = YAML::SequenceStyle::ANY, reference = nil, &) : Nil
¶
(anchor : String? = nil, tag : String? = nil, style : YAML::SequenceStyle = YAML::SequenceStyle::ANY, reference = nil, &) : Nil