Class: DynamicFieldsets::DependencyClause

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dynamic_fieldsets/dependency_clause.rb

Overview

A clause in CNF expression for question dependencies

Author:

  • Jeremiah Hemphill

Instance Method Summary collapse

Instance Method Details

#evaluate(input_values) ⇒ Boolean

Evaluates the depdendencies in the claus by ORing them together Short circuit evaluation returns true as soon as possible

Parameters:

  • input_values (Hash)

    A hash of fieldset_child_id:value pairs to test against

Returns:

  • (Boolean)

    True if one of the dependencies is true



20
21
22
23
24
25
26
27
# File 'app/models/dynamic_fieldsets/dependency_clause.rb', line 20

def evaluate(input_values)
  self.dependencies.each do |dependency|
    if dependency.evaluate
      return true
    end
  end
  return false
end

#to_hashObject



29
30
31
# File 'app/models/dynamic_fieldsets/dependency_clause.rb', line 29

def to_hash
  return { "id" => self.id, "dependency_group_id" => self.dependency_group_id }
end