Class: JSONP3::Path::ChildSegment

Inherits:
Segment
  • Object
show all
Defined in:
lib/json_p3/path/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::Path::Segment

Instance Method Details

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



57
58
59
60
61
# File 'lib/json_p3/path/segment.rb', line 57

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

#hashObject



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

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

#resolve(nodes) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/json_p3/path/segment.rb', line 31

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

#resolve_enum(nodes) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/json_p3/path/segment.rb', line 41

def resolve_enum(nodes)
  Enumerator.new do |yielder|
    nodes.each do |node|
      @selectors.each do |selector|
        selector.resolve(node).each do |item|
          yielder << item
        end
      end
    end
  end
end

#to_sObject



53
54
55
# File 'lib/json_p3/path/segment.rb', line 53

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