Class: Inferno::DSL::ResultCollection
- Inherits:
-
Object
- Object
- Inferno::DSL::ResultCollection
- Includes:
- Enumerable
- Defined in:
- lib/inferno/dsl/result_collection.rb
Overview
The ResultCollection class is used to manage a collection of Inferno::Entities::Result objects. It provides methods to filter required and optional results, access results by index or by their runnable IDs, and iterate over the collection.
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#<<(result) ⇒ Object
-
#[](key) ⇒ Inferno::DSL::Result
If given an integer, returns the result at that index.
-
#each ⇒ Object
-
#initialize(results = []) ⇒ ResultCollection
constructor
A new instance of ResultCollection.
-
#optional_results ⇒ Object
Returns the results for optional runnables.
-
#required_results ⇒ Object
Returns the results for required runnables.
Constructor Details
#initialize(results = []) ⇒ ResultCollection
Returns a new instance of ResultCollection.
38 39 40 |
# File 'lib/inferno/dsl/result_collection.rb', line 38 def initialize(results = []) @results = results end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
36 37 38 |
# File 'lib/inferno/dsl/result_collection.rb', line 36 def results @results end |
Instance Method Details
#<<(result) ⇒ Object
52 53 54 55 |
# File 'lib/inferno/dsl/result_collection.rb', line 52 def <<(result) (results << result).flatten! self end |
#[](key) ⇒ Inferno::DSL::Result
If given an integer, returns the result at that index. If given a string or symbol, it will return the result for the runnable whose id matches the provided string/symbol.
48 49 50 |
# File 'lib/inferno/dsl/result_collection.rb', line 48 def [](key) key.is_a?(Integer) ? results[key] : lookup_by_runnable_id(key) end |
#each ⇒ Object
57 58 59 60 61 62 |
# File 'lib/inferno/dsl/result_collection.rb', line 57 def each(&) return to_enum(:each) unless block_given? results.each(&) self end |
#optional_results ⇒ Object
Returns the results for optional runnables
74 75 76 |
# File 'lib/inferno/dsl/result_collection.rb', line 74 def optional_results results.select(&:optional?) end |
#required_results ⇒ Object
Returns the results for required runnables
67 68 69 |
# File 'lib/inferno/dsl/result_collection.rb', line 67 def required_results results.select(&:required?) end |