Module: Tomlrb
- Defined in:
- lib/tomlrb.rb,
lib/tomlrb/handler.rb,
lib/tomlrb/scanner.rb,
lib/tomlrb/version.rb,
lib/tomlrb/string_utils.rb,
lib/tomlrb/generated_parser.rb
Defined Under Namespace
Classes: GeneratedParser, Handler, ParseError, Parser, Scanner, StringUtils
Constant Summary collapse
- VERSION =
"1.2.3"
Class Method Summary collapse
-
.load_file(path, **options) ⇒ Hash
Reads a file content and parses it into its Ruby data structure.
-
.parse(string_or_io, **options) ⇒ Hash
Parses a valid TOML string into its Ruby data structure.
Class Method Details
.load_file(path, **options) ⇒ Hash
Reads a file content and parses it into its Ruby data structure
37 38 39 |
# File 'lib/tomlrb.rb', line 37 def self.load_file(path, **) Tomlrb.parse(File.read(path), ) end |
.parse(string_or_io, **options) ⇒ Hash
Parses a valid TOML string into its Ruby data structure
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tomlrb.rb', line 18 def self.parse(string_or_io, **) io = string_or_io.is_a?(String) ? StringIO.new(string_or_io) : string_or_io scanner = Scanner.new(io) parser = Parser.new(scanner, ) begin handler = parser.parse rescue Racc::ParseError => e raise ParseError.new(e.) end handler.output end |