Method: JsonQuery::Data.build_paths

Defined in:
lib/json_query/data.rb

.build_paths(path: nil, data:, paths: []) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/json_query/data.rb', line 40

def self.build_paths(path: nil, data:, paths: [])
  if is_set?(data)
    data.map do |key, value|
      new_key = [path, key].compact.join(".")
      paths << new_key
      build_paths(path: new_key, data: value, paths: paths)
    end
  elsif is_list?(data)
    data.map.with_index do |value, index|
      new_key = [path, "[#{index}]"].compact.join
      paths << new_key
      build_paths(path: new_key, data: value, paths: paths)
    end
  else
    # it is a scalar, ignoring
  end
  paths
end