class TOML::Document

Overview

Convenience method on Document itself.

Defined in:

toml.cr
toml/edit.cr
toml/lookup.cr
toml/node.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(nodes : Array(Node) = [] of Node, trailing_raw : String = "") #

[View source]

Instance Method Detail

def bool(path : String) : Bool #

[View source]
def bool?(path : String) : Bool | Nil #

[View source]
def datetime(path : String) : Time #

[View source]
def datetime?(path : String) : Time | Nil #

[View source]
def delete(key : String) : Bool #

Removes the top-level KeyValueLine with the given bare key, if any. Returns true if a line was deleted, false if no such top-level key existed.


[View source]
def float(path : String) : Float64 #

[View source]
def float?(path : String) : Float64 | Nil #

[View source]
def get(path : String) : Type #

[View source]
def get?(path : String) : Type | Nil #

Returns the decoded value at the given dotted path, or nil if the path does not exist or any intermediate segment is not a table.

The path uses . as a separator. Quoted segments are not supported here — if you need a key that contains a dot, use Document#get(path : Array(String)) with an explicit array of segments.


[View source]
def get?(path : Array(String)) : Type | Nil #

[View source]
def has_key?(path : String) : Bool #

[View source]
def int(path : String) : Int64 #

[View source]
def int?(path : String) : Int64 | Nil #

[View source]
def nodes : Array(Node) #

[View source]
def set(key : String, value : String) : Nil #

Sets a top-level key to value. If a top-level KeyValueLine already exists for that key, only its value (and any trailing comment if comment is given) is replaced — surrounding whitespace and comments are preserved. Otherwise a new line is inserted at the end of the top-level section (before the first table header).

comment is the trailing comment text without the leading #. Pass an empty string to clear an existing trailing comment, nil to leave it untouched on update.

The current implementation operates on a single bare key. For dotted paths or values inside [section] blocks, see issue tracker — those are planned but not in v0.1.


[View source]
def set(key : String, value : Int) : Nil #

[View source]
def set(key : String, value : Float) : Nil #

[View source]
def set(key : String, value : Bool) : Nil #

[View source]
def set_with_comment(key : String, value : String, comment : String) : Nil #

Same as #set but also sets a trailing inline comment on the line. The comment argument should not include the leading #; it is added automatically with a single space prefix.


[View source]
def set_with_comment(key : String, value : Int, comment : String) : Nil #

[View source]
def string(path : String) : String #

[View source]
def string?(path : String) : String | Nil #

[View source]
def time_of_day(path : String) : Time::Span #

[View source]
def time_of_day?(path : String) : Time::Span | Nil #

[View source]
def to_h : Hash(String, TOML::Type) #

[View source]
def to_toml(io : IO) : Nil #

[View source]
def to_toml : String #

Re-serialise the document. Byte-identical to the source for any unmodified document.


[View source]
def trailing_raw : String #

[View source]
def trailing_raw=(trailing_raw : String) #

[View source]