class Enumpath::Results
An Array-like structure with syntactical sugar for storing the results of evaluating a path expression against an enumerable.
Constants
- RESULT_TYPE_PATH
- RESULT_TYPE_VALUE
Attributes
result_type[R]
@return [Symbol] the current result type
Public Class Methods
new(result_type: RESULT_TYPE_VALUE)
click to toggle source
@param result_type
[Symbol] the type of result to store, :value (default) or :path
Calls superclass method
# File lib/enumpath/results.rb, line 18 def initialize(result_type: RESULT_TYPE_VALUE) @result_type = result_type super() end
Public Instance Methods
apply(path, options = {})
click to toggle source
Resolve a new path expression against the results of the last path expression
@param path (see Enumpath.apply
) @param options (see Enumpath.apply
) @return (see Enumpath.apply
)
# File lib/enumpath/results.rb, line 28 def apply(path, options = {}) Enumpath.apply(path, self, options) end
store(resolved_path, value)
click to toggle source
Adds a new result to the collection, the format of which is determined by the value of @result_type
@param resolved_path [Array] the path segments leading to the resolved value @param value the resolved value @return [self]
# File lib/enumpath/results.rb, line 37 def store(resolved_path, value) result = if result_type == RESULT_TYPE_PATH as_path(resolved_path) else value end Enumpath.log('New Result') { { result: result } } push(result) end
Private Instance Methods
as_path(resolved_path)
click to toggle source
# File lib/enumpath/results.rb, line 49 def as_path(resolved_path) path = [Enumpath::Operator::ROOT] resolved_path.each do |segment| path << %([#{segment.to_s =~ /^[0-9*]+$/ ? segment : "'#{segment}'"}]) end path.join('') end