Class: Enumpath::Operator::Slice
- Defined in:
- lib/enumpath/operator/slice.rb
Overview
Implements JSONPath array slice operator syntax. See README for syntax and examples
Constant Summary collapse
- OPERATOR_REGEX =
/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.detect?(operator) ⇒ true, false
Whether the operator matches OPERATOR_REGEX.
Instance Method Summary collapse
-
#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object
Yields to the block once for each member of the local enumerable whose index is included by position between start and up to (but not including) end.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Enumpath::Operator::Base
Class Method Details
.detect?(operator) ⇒ true, false
Whether the operator matches OPERATOR_REGEX
14 15 16 |
# File 'lib/enumpath/operator/slice.rb', line 14 def detect?(operator) !(operator =~ OPERATOR_REGEX).nil? end |
Instance Method Details
#apply(remaining_path, enum, resolved_path) {|remaining_path, enum, resolved_path| ... } ⇒ Object
Yields to the block once for each member of the local enumerable whose index is included by position between start and up to (but not including) end. If step is included then only every step member is included, starting with the first.
28 29 30 31 32 33 34 35 |
# File 'lib/enumpath/operator/slice.rb', line 28 def apply(remaining_path, enum, resolved_path) _match, start, length, step = OPERATOR_REGEX.match(operator).to_a max_length = enum.size slices(start, length, step, max_length).each do |index| Enumpath.log('Applying slice') { { slice: index } } yield([index.to_s] + remaining_path, enum, resolved_path) end end |