Class: Braintrust::Eval::Cases
- Inherits:
-
Object
- Object
- Braintrust::Eval::Cases
- Includes:
- Enumerable
- Defined in:
- lib/braintrust/eval/cases.rb
Overview
Cases wraps test case data (arrays or enumerables) and normalizes them to Case objects Supports lazy evaluation for memory-efficient processing of large datasets
Instance Method Summary collapse
-
#count ⇒ Integer
Get the count of cases Note: For lazy enumerators, this will force evaluation.
-
#each {|Case| ... } ⇒ Object
Iterate over cases, normalizing each to a Case object.
-
#initialize(enumerable) ⇒ Cases
constructor
Create a new Cases wrapper.
Constructor Details
#initialize(enumerable) ⇒ Cases
Create a new Cases wrapper
14 15 16 17 18 19 20 |
# File 'lib/braintrust/eval/cases.rb', line 14 def initialize(enumerable) unless enumerable.respond_to?(:each) raise ArgumentError, "Cases must be enumerable (respond to :each)" end @enumerable = enumerable end |
Instance Method Details
#count ⇒ Integer
Get the count of cases Note: For lazy enumerators, this will force evaluation
35 36 37 |
# File 'lib/braintrust/eval/cases.rb', line 35 def count @enumerable.count end |
#each {|Case| ... } ⇒ Object
Iterate over cases, normalizing each to a Case object
24 25 26 27 28 29 30 |
# File 'lib/braintrust/eval/cases.rb', line 24 def each return enum_for(:each) unless block_given? @enumerable.each do |item| yield normalize_case(item) end end |