Sha256: c9b46ac49a8b9eaaf716f7f86eadb92fd7d42a8bc56df8910210c825a83f52af
Contents?: true
Size: 1.28 KB
Versions: 6
Compression:
Stored size: 1.28 KB
Contents
require 'time' require 'stringio' require "tomlrb/version" require 'tomlrb/string_utils' require "tomlrb/scanner" require "tomlrb/parser" require "tomlrb/handler" module Tomlrb class ParseError < StandardError; end # Parses a valid TOML string into its Ruby data structure # # @param string_or_io [String, StringIO] the content # @param options [Hash] the options hash # @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings # @return [Hash] the Ruby data structure represented by the input def self.parse(string_or_io, **options) io = string_or_io.is_a?(String) ? StringIO.new(string_or_io) : string_or_io scanner = Scanner.new(io) parser = Parser.new(scanner, options) begin handler = parser.parse rescue Racc::ParseError => e raise ParseError.new(e.message) end handler.output end # Reads a file content and parses it into its Ruby data structure # # @param path [String] the path to the file # @param options [Hash] the options hash # @option options [Boolean] :symbolize_keys (false) whether to return the keys as symbols or strings # @return [Hash] the Ruby data structure represented by the input def self.load_file(path, **options) Tomlrb.parse(File.read(path), options) end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
tomlrb-1.2.4 | lib/tomlrb.rb |
tomlrb-1.2.3 | lib/tomlrb.rb |
tomlrb-1.2.2 | lib/tomlrb.rb |
tomlrb-1.2.1 | lib/tomlrb.rb |
tomlrb-1.2.0 | lib/tomlrb.rb |
tomlrb-1.1.3 | lib/tomlrb.rb |