Module: TomlRB
- Defined in:
- lib/toml-rb.rb,
lib/toml-rb/array.rb,
lib/toml-rb/table.rb,
lib/toml-rb/dumper.rb,
lib/toml-rb/errors.rb,
lib/toml-rb/parser.rb,
lib/toml-rb/string.rb,
lib/toml-rb/version.rb,
lib/toml-rb/datetime.rb,
lib/toml-rb/keyvalue.rb,
lib/toml-rb/table_array.rb,
lib/toml-rb/inline_table.rb
Defined Under Namespace
Modules: ArrayParser, BasicString, InlineTableParser, KeyvalueParser, LiteralString, LocalDateParser, LocalDateTimeParser, LocalTimeParser, MultilineLiteral, MultilineString, OffsetDateTimeParser, TableArrayParser, TableParser Classes: Dumper, InlineTable, Keyvalue, Parser, Table, TableArray, ValueOverwriteError
Constant Summary collapse
- Error =
Parent class for all TomlRB errors
Class.new(StandardError)
- ParseError =
Error related to parsing.
Class.new(Error)
- VERSION =
"3.0.1"
Class Method Summary collapse
-
.dump(hash) ⇒ Object
Public: Returns a TomlRB string from a Ruby Hash.
-
.load_file(path, symbolize_keys: false) ⇒ Object
Public: Returns a hash from a TomlRB file.
-
.parse(content, symbolize_keys: false) ⇒ Object
Public: Returns a hash from TomlRB content.
Class Method Details
.dump(hash) ⇒ Object
Public: Returns a TomlRB string from a Ruby Hash.
hash - Ruby Hash to be dumped into TomlRB
Examples
TomlRB.dump(title: 'TomlRB dump')
# => "simple = true\n"
hash = {
"title"=>"wow!",
"awesome"=> {
"you"=>true,
"others"=>false
}
}
TomlRB.dump(hash)
# => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"
Returns a TomlRB string representing the hash.
97 98 99 |
# File 'lib/toml-rb.rb', line 97 def self.dump(hash) Dumper.new(hash).toml_str end |
.load_file(path, symbolize_keys: false) ⇒ Object
Public: Returns a hash from a TomlRB file.
path - TomlRB File path :symbolize_keys - true|false (optional).
Examples
TomlRB.load_file('/tmp/simple.toml')
# => {"group"=>{}}
TomlRB.load_file('/tmp/simple.toml', symbolize_keys: true)
# => {group: {}}
Returns a Ruby hash representation of the content. Raises ValueOverwriteError if a key is overwritten. Raises ParseError if the content has invalid TomlRB. Raises Errno::ENOENT if the file cannot be found. Raises Errno::EACCES if the file cannot be accessed.
70 71 72 |
# File 'lib/toml-rb.rb', line 70 def self.load_file(path, symbolize_keys: false) TomlRB.parse(File.read(path), symbolize_keys: symbolize_keys) end |
.parse(content, symbolize_keys: false) ⇒ Object
Public: Returns a hash from TomlRB content.
content - TomlRB string to be parsed. :symbolize_keys - true | false (default: false).
Examples
TomlRB.parse('[group]')
# => {"group"=>{}}
TomlRB.parse('title = "TomlRB parser"')
# => {"title"=>"TomlRB parser"}
TomlRB.parse('[group]', symbolize_keys: true)
# => {group: {}}
TomlRB.parse('title = "TomlRB parser"', symbolize_keys: true)
# => {title: "TomlRB parser"}
Returns a Ruby hash representation of the content according to TomlRB spec. Raises ValueOverwriteError if a key is overwritten. Raises ParseError if the content has invalid TomlRB.
46 47 48 |
# File 'lib/toml-rb.rb', line 46 def self.parse(content, symbolize_keys: false) Parser.new(content, symbolize_keys: symbolize_keys).hash end |