Sha256: 8f722fc478de08b56afc73fe991a9bc1bdab063a1b5b6ef3f5132f03bc222f08

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

require_relative "../init"

module TOML

  # 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
  def self.parse(content, options = {})
    Parser.new(content, options).hash
  end

  # 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 Errno::ENOENT if the file cannot be found.
  # Raises Errno::EACCES if the file cannot be accessed.
  def self.load_file(path, options = {})
    TOML.parse(File.read(path), options)
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
toml-rb-0.1.0 lib/toml.rb
toml_parser-ruby-0.1.0 lib/toml.rb