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 = [] @fully_defined_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_keyvalue(keyvalue)
click to toggle source
# File lib/toml-rb/parser.rb, line 35 def visit_keyvalue(keyvalue) keyvalue.assign @current, @fully_defined_keys, @symbolize_keys end
visit_table(table)
click to toggle source
# File lib/toml-rb/parser.rb, line 30 def visit_table(table) @fully_defined_keys = [] @current = table.navigate_keys @hash, @visited_keys, @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 22 def visit_table_array(table_array) @fully_defined_keys = [] 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