Class: Inferno::ResultCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/inferno/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.

Examples:


results = [
  Result.new(test_group_id: 'group_id1', result: 'pass'),
  Result.new(test_group_id: 'group_id2', result: 'fail'),
  Result.new(test_group_id: 'group_id3', result: 'pass')
]

result_collection = Inferno::ResultCollection.new(results)

# Access by index
result = result_collection[0]

# Access by runnable ID (partial)
result = result_collection['group_id2']

# Iterate over results
result_collection.each do |result|
  puts result.result
end

# Get required results
required_results = result_collection.required_results

# Get optional results
optional_results = result_collection.optional_results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results = []) ⇒ ResultCollection

Returns a new instance of ResultCollection.



38
39
40
# File 'lib/inferno/result_collection.rb', line 38

def initialize(results = [])
  @results = results
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



36
37
38
# File 'lib/inferno/result_collection.rb', line 36

def results
  @results
end

Instance Method Details

#<<(result) ⇒ Object



46
47
48
49
# File 'lib/inferno/result_collection.rb', line 46

def <<(result)
  (results << result).flatten!
  self
end

#[](key) ⇒ Object



42
43
44
# File 'lib/inferno/result_collection.rb', line 42

def [](key)
  key.is_a?(Integer) ? results[key] : lookup_by_runnable_id(key)
end

#eachObject



51
52
53
54
55
56
# File 'lib/inferno/result_collection.rb', line 51

def each(&)
  return to_enum(:each) unless block_given?

  results.each(&)
  self
end

#optional_resultsObject



62
63
64
# File 'lib/inferno/result_collection.rb', line 62

def optional_results
  results.select(&:optional?)
end

#required_resultsObject



58
59
60
# File 'lib/inferno/result_collection.rb', line 58

def required_results
  results.select(&:required?)
end