Sha256: 707f0a5c7e53ad0e30094d93ab4df6041695db503daa21224a0c692d2f472245

Contents?: true

Size: 936 Bytes

Versions: 3

Compression:

Stored size: 936 Bytes

Contents

module DynamicFieldsets
  # A clause in CNF expression for question dependencies
  #
  # @author Jeremiah Hemphill
  class DependencyClause < ActiveRecord::Base
    belongs_to :dependency_group  

    has_many :dependencies
    accepts_nested_attributes_for :dependencies, :allow_destroy => true

    validates_presence_of :dependency_group_id

    # Evaluates the depdendencies in the claus by ORing them together
    # Short circuit evaluation returns true as soon as possible
    #
    # @param [Hash] input_values A hash of fieldset_child_id:value pairs to test against
    # @return [Boolean] True if one of the dependencies is true
    def evaluate(input_values)
      self.dependencies.each do |dependency|
        if dependency.evaluate
          return true
        end
      end
      return false
    end

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dynamic_fieldsets-0.0.6 app/models/dynamic_fieldsets/dependency_clause.rb
dynamic_fieldsets-0.0.5 app/models/dynamic_fieldsets/dependency_clause.rb
dynamic_fieldsets-0.0.4 app/models/dynamic_fieldsets/dependency_clause.rb