Sha256: aa73f4645b99d69cce8e4076148b027077b91150c0057ab8c67015b017d6d49c

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

module TOML
  class TableArray
    def initialize(nested_keys)
      @nested_keys = nested_keys
    end

    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
      hash[last_key] = [] unless hash[last_key]
      hash[last_key] << {}

      hash[last_key].last
    end

    def accept_visitor(parser)
      parser.visit_table_array self
    end
  end

  # Used in document.citrus
  module TableArrayParser
    def value
      TOML::TableArray.new(captures[:key].map(&:value))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
toml-rb-0.3.6 lib/toml/table_array.rb