Class: JSONPath::Nodes::WildcardNode

Inherits:
PathNode
  • Object
show all
Defined in:
lib/jsonpath/nodes.rb

Instance Method Summary collapse

Methods inherited from PathNode

#recurse, #traverse, #traversing_descendants?

Instance Method Details

#descend(*objects) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/jsonpath/nodes.rb', line 47

def descend(*objects)
  results = []
  traverse(objects) do |obj|
    values = case obj
    when Hash
      obj.values
    when Array
      obj
    else
      next
    end
    results.push(*values)
    # Note: I really don't like this special case.  This happens
    # because when wildcarding regularly, the results are the *children*,
    # but when using a .. descendant selector, you want the main parent,
    # too.  According to the JSONPath docs, '$..*' means "All members of
    # [the] JSON structure."  Should this support Array, as well?
    if obj.is_a?(Hash) && traversing_descendants?
      results.push(obj) unless results.include?(obj)
    end
  end
  results
end