Class: TomlRB::Table
- Inherits:
-
Object
- Object
- TomlRB::Table
- Defined in:
- lib/toml-rb/table.rb
Instance Method Summary collapse
- #accept_visitor(parser) ⇒ Object
- #full_key ⇒ Object
-
#initialize(dotted_keys) ⇒ Table
constructor
A new instance of Table.
- #navigate_keys(hash, visited_keys, symbolize_keys = false) ⇒ Object
Constructor Details
#initialize(dotted_keys) ⇒ Table
Returns a new instance of Table.
3 4 5 |
# File 'lib/toml-rb/table.rb', line 3 def initialize(dotted_keys) @dotted_keys = dotted_keys end |
Instance Method Details
#accept_visitor(parser) ⇒ Object
21 22 23 |
# File 'lib/toml-rb/table.rb', line 21 def accept_visitor(parser) parser.visit_table self end |
#full_key ⇒ Object
25 26 27 |
# File 'lib/toml-rb/table.rb', line 25 def full_key @dotted_keys.join(".") end |
#navigate_keys(hash, visited_keys, symbolize_keys = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/toml-rb/table.rb', line 7 def navigate_keys(hash, visited_keys, symbolize_keys = false) ensure_key_not_defined(visited_keys) current = hash keys = symbolize_keys ? @dotted_keys.map(&:to_sym) : @dotted_keys keys.each do |key| current[key] = {} unless current.key?(key) element = current[key] current = element.is_a?(Array) ? element.last : element # check that key has not been defined before as a scalar value fail ValueOverwriteError.new(key) unless current.is_a?(Hash) end current end |