class RemiLib::RSConf::Writer

Overview

The Writer class is used to generate properly-formatted RSConf data from RSValues. There is also the RemiLib::RSConf::Builder class, which is much more flexible.

require "libremiliacr"

root = RemiLib::RSConf::RSObject.new
root["test"] = 69
root["test2"] = "Hello, world!"

io = IO::Memory.new
writer = RemiLib::RSConf::Writer.new(io)
writer.write(root)
puts io.to_s

Defined in:

remilib/rsconf/writer.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Object

toRsconf(io : IO, *, indentSize : Int = 2, alwaysQuoteKeys : Bool = false, explicitRootObject : Bool = false, commaAfterValues : Bool = false, extraNewlineBetweenToplevelKeys : Bool = false) : Nil
toRsconf(*, indentSize : Int = 2, alwaysQuoteKeys : Bool = false, explicitRootObject : Bool = false, commaAfterValues : Bool = false, extraNewlineBetweenToplevelKeys : Bool = false) : String
toRsconf

Class methods inherited from class Object

fromRsconf(toplevel : RemiLib::RSConf::RSValue)
fromRsconf(data : String | IO | Path)
fromRsconf

Constructor Detail

def self.new(stream : IO) #

Creates a new Writer instance that will write data to stream.


[View source]

Class Method Detail

def self.write(dest : IO, data : RSTopLevel) : Nil #

Writes RSConf data to the given IO.


[View source]
def self.write(data : RSTopLevel) : String #

Writes RSConf data to a new string and returns it.


[View source]

Instance Method Detail

def alwaysQuoteKeys=(alwaysQuoteKeys : Bool) #

When true, then key names are always quoted, even when they don't need to be. Otherwise they are only quoted when necessary.


[View source]
def alwaysQuoteKeys? : Bool #

When true, then key names are always quoted, even when they don't need to be. Otherwise they are only quoted when necessary.


[View source]
def alwaysUseScientificNotation=(alwaysUseScientificNotation : Bool) #

When true, then float values are always written using scientific notation.


[View source]
def alwaysUseScientificNotation? : Bool #

When true, then float values are always written using scientific notation.


[View source]
def commaAfterValues=(commaAfterValues : Bool) #

When true, then a comma is always inserted after values, otherwise commas are omitted.


[View source]
def commaAfterValues? : Bool #

When true, then a comma is always inserted after values, otherwise commas are omitted.


[View source]
def explicitRootObject=(explicitRootObject : Bool) #

When true, and the toplevel value is an RSObject, then braces will be inserted around it (similar to JSON). Otherwise these are omitted, as permitted by the specs.


[View source]
def explicitRootObject? : Bool #

When true, and the toplevel value is an RSObject, then braces will be inserted around it (similar to JSON). Otherwise these are omitted, as permitted by the specs.


[View source]
def extraNewlineBetweenToplevelKeys=(extraNewlineBetweenToplevelKeys : Bool) #

When true, then an extra newline is added after every topevel key/value pair (i.e., an extra blank line between each pair). Otherwise only a single newline is emitted after each pair.


[View source]
def extraNewlineBetweenToplevelKeys? : Bool #

When true, then an extra newline is added after every topevel key/value pair (i.e., an extra blank line between each pair). Otherwise only a single newline is emitted after each pair.


[View source]
def indentSize : UInt32 #

The size of the indent (ASCII spaces).


[View source]
def indentSize=(indentSize : UInt32) #

The size of the indent (ASCII spaces).


[View source]
def stream : IO #

Returns the underlying IO.


[View source]
def stream=(value : IO) : Nil #

Changes the destination stream. Calling this effectively "resets" the Writer instance, allowing you to call #write again to generate new RSConf data. The old stream is NOT closed.


[View source]
def write(data : RSObject) : Nil #

Writes the toplevel RSObject value. After this, no more writing can happen until #stream= is called.


[View source]
def write(data : RSArray) : Nil #

Writes the toplevel RSArray value. After this, no more writing can happen until #stream= is called.


[View source]