Class: Enumpath::Results
- Inherits:
-
Array
- Object
- Array
- Enumpath::Results
- Defined in:
- lib/enumpath/results.rb
Overview
An Array-like structure with syntactical sugar for storing the results of evaluating a path expression against an enumerable.
Constant Summary collapse
- RESULT_TYPE_PATH =
:path
- RESULT_TYPE_VALUE =
:value
Instance Attribute Summary collapse
-
#result_type ⇒ Symbol
readonly
The current result type.
Instance Method Summary collapse
-
#apply(path, options = {}) ⇒ Enumpath::Results
Resolve a new path expression against the results of the last path expression.
-
#initialize(result_type: RESULT_TYPE_VALUE) ⇒ Results
constructor
A new instance of Results.
-
#store(resolved_path, value) ⇒ self
Adds a new result to the collection, the format of which is determined by the value of @result_type.
Constructor Details
#initialize(result_type: RESULT_TYPE_VALUE) ⇒ Results
Returns a new instance of Results.
18 19 20 21 |
# File 'lib/enumpath/results.rb', line 18 def initialize(result_type: RESULT_TYPE_VALUE) @result_type = result_type super() end |
Instance Attribute Details
#result_type ⇒ Symbol (readonly)
Returns the current result type.
15 16 17 |
# File 'lib/enumpath/results.rb', line 15 def result_type @result_type end |
Instance Method Details
#apply(path, options = {}) ⇒ Enumpath::Results
Resolve a new path expression against the results of the last path expression
28 29 30 |
# File 'lib/enumpath/results.rb', line 28 def apply(path, = {}) Enumpath.apply(path, self, ) end |
#store(resolved_path, value) ⇒ self
Adds a new result to the collection, the format of which is determined by the value of @result_type
37 38 39 40 41 42 43 44 45 |
# 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 |