Class: Retab::AssertionSpec

Inherits:
Types::BaseModel show all
Defined in:
lib/retab/workflow_tests/assertion_spec.rb

Constant Summary collapse

HASH_ATTRS =
{
  id: :id,
  target: :target,
  condition: :condition,
  label: :label
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Types::BaseModel

#last_response

Instance Method Summary collapse

Methods inherited from Types::BaseModel

deep_symbolize, #inspect, normalize, #to_h, #to_json

Constructor Details

#initialize(json) ⇒ AssertionSpec

Returns a new instance of AssertionSpec.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/retab/workflow_tests/assertion_spec.rb', line 22

def initialize(json)
  super()
  hash = self.class.normalize(json)
  @id = hash[:id]
  @target = hash[:target] ? Retab::OutputTarget.new(hash[:target]) : nil
  @condition = hash[:condition] ? (
    case hash[:condition][:kind]
    when "all_items_match"
      Retab::AllItemsMatchCondition.new(hash[:condition])
    when "any_item_matches"
      Retab::AnyItemMatchesCondition.new(hash[:condition])
    when "array_contains"
      Retab::ArrayContainsCondition.new(hash[:condition])
    when "between"
      Retab::BetweenCondition.new(hash[:condition])
    when "ends_with"
      Retab::EndsWithCondition.new(hash[:condition])
    when "json_schema_valid"
      Retab::JsonSchemaValidCondition.new(hash[:condition])
    when "length_compare"
      Retab::LengthCompareCondition.new(hash[:condition])
    when "llm_judged_as"
      Retab::LlmJudgedAsCondition.new(hash[:condition])
    when "llm_not_judged_as"
      Retab::LlmNotJudgedAsCondition.new(hash[:condition])
    when "not_contains"
      Retab::NotContainsCondition.new(hash[:condition])
    when "not_equals"
      Retab::NotEqualsCondition.new(hash[:condition])
    when "not_exists"
      Retab::NotExistsCondition.new(hash[:condition])
    when "number_compare"
      Retab::NumberCompareCondition.new(hash[:condition])
    when "object_contains"
      Retab::ObjectContainsCondition.new(hash[:condition])
    when "similarity_gte"
      Retab::SimilarityGteCondition.new(hash[:condition])
    else
      hash[:condition]
    end
  ) : nil
  @label = hash[:label]
end

Instance Attribute Details

#conditionObject

Returns the value of attribute condition.



15
16
17
# File 'lib/retab/workflow_tests/assertion_spec.rb', line 15

def condition
  @condition
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/retab/workflow_tests/assertion_spec.rb', line 15

def id
  @id
end

#labelObject

Returns the value of attribute label.



15
16
17
# File 'lib/retab/workflow_tests/assertion_spec.rb', line 15

def label
  @label
end

#targetObject

Returns the value of attribute target.



15
16
17
# File 'lib/retab/workflow_tests/assertion_spec.rb', line 15

def target
  @target
end