Class: JSONP3::ChildSegment

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

Overview

The child selection 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?



37
38
39
40
41
# File 'lib/json_p3/segment.rb', line 37

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

#hashObject



45
46
47
# File 'lib/json_p3/segment.rb', line 45

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

#resolve(nodes) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/json_p3/segment.rb', line 23

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

#to_sObject



33
34
35
# File 'lib/json_p3/segment.rb', line 33

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