Module: TOML
- Defined in:
- lib/toml.rb,
lib/toml/dumper.rb,
lib/toml/errors.rb,
lib/toml/parser.rb,
lib/toml/string.rb,
lib/toml/keygroup.rb,
lib/toml/keyvalue.rb,
lib/toml/table_array.rb,
lib/toml/inline_table.rb
Defined Under Namespace
Modules: BasicString, InlineTableArrayParser, InlineTableParser, KeygroupParser, KeyvalueParser, LiteralString, MultilineLiteral, MultilineString, TableArrayParser Classes: Dumper, InlineTable, InlineTableArray, Keygroup, Keyvalue, Parser, TableArray, ValueOverwriteError
Constant Summary collapse
- Error =
Parent class for all TOML errors
Class.new(StandardError)
- ParseError =
Error related to parsing.
Class.new(Error)
Class Method Summary collapse
-
.dump(hash) ⇒ Object
Public: Returns a TOML string from a Ruby Hash.
-
.load_file(path, options = {}) ⇒ Object
Public: Returns a hash from a TOML file.
-
.parse(content, options = {}) ⇒ Object
Public: Returns a hash from TOML content.
Class Method Details
.dump(hash) ⇒ Object
Public: Returns a TOML string from a Ruby Hash.
hash - Ruby Hash to be dumped into TOML
Examples
TOML.dump(title: 'TOML dump')
# => "simple = true\n"
hash = {
"title"=>"wow!",
"awesome"=> {
"you"=>true,
"others"=>false
}
}
TOML.dump(hash)
# => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"
Returns a TOML string representing the hash.
81 82 83 |
# File 'lib/toml.rb', line 81 def self.dump(hash) Dumper.new(hash).toml_str end |
.load_file(path, options = {}) ⇒ Object
Public: Returns a hash from a TOML file.
path - TOML File path options - The Hash options used to refine the parser (default: {}):
:symbolize_keys - true|false (optional).
Examples
TOML.load_file('/tmp/simple.toml')
# => {"group"=>{}}
TOML.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 TOML. Raises Errno::ENOENT if the file cannot be found. Raises Errno::EACCES if the file cannot be accessed.
54 55 56 |
# File 'lib/toml.rb', line 54 def self.load_file(path, = {}) TOML.parse(File.read(path), ) end |
.parse(content, options = {}) ⇒ Object
Public: Returns a hash from TOML content.
content - TOML string to be parsed. options - The Hash options used to refine the parser (default: {}):
:symbolize_keys - true|false (optional).
Examples
TOML.parse('[group]')
# => {"group"=>{}}
TOML.parse('title = "TOML parser"')
# => {"title"=>"TOML parser"}
TOML.parse('[group]', symbolize_keys: true)
# => {group: {}}
TOML.parse('title = "TOML parser"', symbolize_keys: true)
# => {title: "TOML parser"}
Returns a Ruby hash representation of the content according to TOML spec. Raises ValueOverwriteError if a key is overwritten. Raises ParseError if the content has invalid TOML.
29 30 31 |
# File 'lib/toml.rb', line 29 def self.parse(content, = {}) Parser.new(content, ).hash end |