Oyl::Builder
Writes YAML with Oyl's emitter: a stream of documents, each holding one
node. #write writes a Crystal value so that it reads back as the same
value; #scalar, #sequence and #mapping write what they are given.
yaml = Oyl::Builder.build do |b|
b.document do
b.mapping do
b.write "name"
b.write "oyl"
b.write "fast"
b.write true
end
end
end
yaml # => "name: oyl\nfast: true\n"
Constants
Constructors
Class methods
Yields a builder and returns the YAML it wrote.
Instance methods
Writes a document around what the block writes. --- and ... are
written where YAML needs them, or always with explicit_start and
explicit_end.
Writes a mapping of what the block writes: a key, then its value.
Writes value as a scalar's text. With ScalarStyle::ANY (or
PLAIN) it is written plain when that reads back as the same text,
else quoted; YAML may still read that text as another type (true).
tag is a full tag (tag:yaml.org,2002:str, written !!str) or a
local one (!foo).
Writes a sequence of what the block writes.
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Writes value so that Oyl.parse reads it back as the same value,
whatever its dialect: a string is quoted where YAML 1.2, YAML 1.1 or
go-yaml v2 would read it as another type ("yes", "1:30", ""),
and written as a literal block when it has line breaks. YAML 1.2 has
no plain form for Time and Bytes, so they are tagged !!timestamp
and !!binary. Each type writes itself with to_oyl(builder), which
a type of your own can define.