Module: JsonQuery

Defined in:
lib/json_query.rb,
lib/json_query/data.rb,
lib/json_query/version.rb,
lib/json_query/composite_path.rb,
lib/json_query/composite_query.rb,
lib/json_query/query_match_results.rb

Defined Under Namespace

Modules: Data Classes: CompositePath, CompositeQuery, QueryMatchResults

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.perform(data:, query:, deep: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/json_query.rb', line 10

def self.perform(data:, query:, deep: false)
  paths = Data::build_paths(data: data).map do |path|
    CompositePath.new(base: path, segments: path.split("."))
  end
  expand_query(query: query).map do |query|
    match_query_against_paths(query: query, paths: paths, data: data)
  end.select(&:has_matching_paths?).map do |query_match_results|
    query_match_results.paths.map do |path|
      {
        value: Data::walk(path: path.segments, data: data),
        path: path.base
      }
    end
  end.flatten.map do |result|
    {
      path: result[:path],
      value: deep_value(value: result[:value], deep: deep)
    }
  end
end