Class: JSONP3::RecursiveDescentSegment

Inherits:
Segment
  • Object
show all
Defined in:
lib/json_p3/segment.rb

Overview

The recursive descent segment

Instance Attribute Summary

Attributes inherited from Segment

#selectors, #token

Instance Method Summary collapse

Methods inherited from Segment

#initialize

Constructor Details

This class inherits a constructor from JSONP3::Segment

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



68
69
70
71
72
# File 'lib/json_p3/segment.rb', line 68

def ==(other)
  self.class == other.class &&
    @selectors == other.selectors &&
    @token == other.token
end

#hashObject



76
77
78
# File 'lib/json_p3/segment.rb', line 76

def hash
  ["..", @selectors, @token].hash
end

#resolve(nodes) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/json_p3/segment.rb', line 52

def resolve(nodes)
  rv = [] # : Array[JSONPathNode]
  nodes.each do |node|
    visit(node).each do |descendant|
      @selectors.each do |selector|
        rv.concat selector.resolve(descendant)
      end
    end
  end
  rv
end

#to_sObject



64
65
66
# File 'lib/json_p3/segment.rb', line 64

def to_s
  "..[#{@selectors.map(&:to_s).join(", ")}]"
end