class TomlRB::Parser

Attributes

hash[R]

Public Class Methods

new(content, options = {}) click to toggle source
# File lib/toml-rb/parser.rb, line 5
def initialize(content, options = {})
  @hash = {}
  @visited_keys = []
  @current = @hash
  @symbolize_keys = options[:symbolize_keys]

  begin
    parsed = TomlRB::Document.parse(content)
    parsed.matches.map(&:value).compact.each { |m| m.accept_visitor(self) }
  rescue Citrus::ParseError => e
    raise TomlRB::ParseError.new(e.message)
  end
end

Public Instance Methods

visit_keygroup(keygroup) click to toggle source
# File lib/toml-rb/parser.rb, line 28
def visit_keygroup(keygroup)
  @current = keygroup.navigate_keys @hash, @visited_keys, @symbolize_keys
end
visit_keyvalue(keyvalue) click to toggle source
# File lib/toml-rb/parser.rb, line 32
def visit_keyvalue(keyvalue)
  keyvalue.assign @current, @symbolize_keys
end
visit_table_array(table_array) click to toggle source

Read about the Visitor pattern en.wikipedia.org/wiki/Visitor_pattern

# File lib/toml-rb/parser.rb, line 21
def visit_table_array(table_array)
  table_array_key = table_array.full_key
  @visited_keys.reject! { |k| k.start_with? table_array_key }

  @current = table_array.navigate_keys @hash, @symbolize_keys
end