Sha256: f68a415d7cfd44ee154ec5f41b3bb041aa8aa6994749e385339146d351bda38c

Contents?: true

Size: 966 Bytes

Versions: 1

Compression:

Stored size: 966 Bytes

Contents

# frozen_string_literal: true

require_relative 'rule_evaluator'

# undoc
class RuleProcessor
  # /**
  #  * @param scenario current scenario.
  #  * @param caseFixture current test case fixture.
  #  */
  def evaluate(scenario: [], fixture: nil)
    # if scenario.empty? || fixture.nil?
    #   raise 'Scenario or fixture cannot be nil.'
    # end

    fixture[:spec].rule.outcomes.inject([]) do |retval, outcome|
      process_outcome(
        scenario: scenario,
        fixture: fixture,
        list: retval,
        outcome: outcome
      )
    end
  end

  private

  def process_outcome(scenario: [], fixture: nil, list: [], outcome: '')
    spec = fixture[:spec]

    clause = spec.rule.clause(outcome: outcome)
    rule_evaluator = RuleEvaluator.new(converters: spec.converters)

    rule_evaluator.parse(expression: clause)

    list << rule_evaluator.evaluate(
      scenario: scenario,
      rule_token_convert: fixture[:converter_hash]
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rast-0.1.0.pre lib/rast/rules/rule_processor.rb