Class: TOML::TableArray
- Inherits:
-
Object
- Object
- TOML::TableArray
- Defined in:
- lib/toml/table_array.rb
Instance Method Summary collapse
- #accept_visitor(parser) ⇒ Object
-
#initialize(nested_keys) ⇒ TableArray
constructor
A new instance of TableArray.
- #navigate_keys(hash, symbolize_keys = false) ⇒ Object
Constructor Details
#initialize(nested_keys) ⇒ TableArray
Returns a new instance of TableArray.
3 4 5 |
# File 'lib/toml/table_array.rb', line 3 def initialize(nested_keys) @nested_keys = nested_keys end |
Instance Method Details
#accept_visitor(parser) ⇒ Object
34 35 36 |
# File 'lib/toml/table_array.rb', line 34 def accept_visitor(parser) parser.visit_table_array self end |
#navigate_keys(hash, symbolize_keys = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/toml/table_array.rb', line 7 def navigate_keys(hash, symbolize_keys = false) last_key = @nested_keys.pop # Go over the parent keys @nested_keys.each do |key| key = symbolize_keys ? key.to_sym : key hash[key] = {} unless hash[key] if hash[key].is_a? Array hash[key] << {} if hash[key].empty? hash = hash[key].last else hash = hash[key] end end # Define Table Array if hash[last_key].is_a? Hash fail TOML::ParseError, "#{last_key} was defined as hash but is now redefined as a table!" end hash[last_key] = [] unless hash[last_key] hash[last_key] << {} hash[last_key].last end |