Class: Philiprehberger::TomlKit::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/toml_kit/parser.rb

Overview

TOML v1.0 parser.

Parses a TOML string into a Ruby Hash with proper type mapping:

- Strings -> String
- Integers -> Integer
- Floats -> Float
- Booleans -> true/false
- Offset Date-Time -> Time
- Local Date-Time -> Time (local)
- Local Date -> Date
- Local Time -> Hash with :hour, :minute, :second keys
- Arrays -> Array
- Inline Tables -> Hash
- Tables -> Hash (nested)
- Array of Tables -> Array of Hashes

Instance Method Summary collapse

Instance Method Details

#parse(input) ⇒ Hash

Returns parsed result.

Parameters:

  • input (String)

    TOML document

Returns:

  • (Hash)

    parsed result



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/philiprehberger/toml_kit/parser.rb', line 27

def parse(input)
  @scanner = StringScanner.new(input)
  @result = {}
  @current_table = @result
  @current_path = []
  @implicit_tables = {}
  @defined_tables = {}
  @defined_array_tables = {}

  parse_document
  @result
end