Class: JSONPath::Nodes::SliceNode
- Inherits:
-
PathNode
- Object
- Treetop::Runtime::SyntaxNode
- PathNode
- JSONPath::Nodes::SliceNode
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
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/jsonpath/nodes.rb', line 120
def descend(*objects)
results = []
traverse(objects) do |obj|
if obj.is_a?(Array)
values = obj[start_offset..stop_offset(obj)]
0.step(values.size - 1, step_size) do |n|
results << values[n]
end
end
end
results
end
|
#start_offset ⇒ Object
133
134
135
|
# File 'lib/jsonpath/nodes.rb', line 133
def start_offset
@start_offset ||= Integer(start.text_value)
end
|
#step_size ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/jsonpath/nodes.rb', line 145
def step_size
@step_size ||= if respond_to?(:step)
Integer(step.text_value)
else
1
end
end
|
#stop_offset(obj) ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/jsonpath/nodes.rb', line 137
def stop_offset(obj)
@stop_offset ||= if respond_to?(:stop)
Integer(stop.text_value)
else
obj.size
end
end
|