Class: DependencyCondition

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Surveyor::Models::DependencyConditionMethods
Defined in:
lib/surveyor/parser.rb,
lib/surveyor/unparser.rb,
lib/surveyor/redcap_parser.rb,
app/models/dependency_condition.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Surveyor::Models::DependencyConditionMethods

included, #is_met?, #to_hash

Instance Attribute Details

- (Object) answer_reference

nonblock



181
182
183
# File 'lib/surveyor/parser.rb', line 181

def answer_reference
  @answer_reference
end

- (Object) context_reference

nonblock



181
182
183
# File 'lib/surveyor/parser.rb', line 181

def context_reference
  @context_reference
end

- (Object) lookup_reference

Returns the value of attribute lookup_reference



156
157
158
# File 'lib/surveyor/redcap_parser.rb', line 156

def lookup_reference
  @lookup_reference
end

- (Object) question_reference

nonblock



181
182
183
# File 'lib/surveyor/parser.rb', line 181

def question_reference
  @question_reference
end

Class Method Details

+ (Object) parse_and_build(context, args, original_method, reference_identifier)



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/surveyor/parser.rb', line 184

def self.parse_and_build(context, args, original_method, reference_identifier)
  # clear context
  context.delete_if{|k,v| k == :dependency_condition}
  
  # build and set context
  a0, a1, a2 = args
  context[:dependency_condition] = context[:dependency].
    dependency_conditions.build(
      { 
        :context_reference => context,
        :operator => a1 || "==",
        :question_reference => a0.to_s.gsub("q_", ""),
        :rule_key => reference_identifier 
      }.merge(
          a2.is_a?(Hash) ? a2 : { :answer_reference => 
                                    a2.to_s.gsub("a_", "") }
        )
    )
end

Instance Method Details

- (Object) resolve_references



204
205
206
207
208
209
210
211
# File 'lib/surveyor/parser.rb', line 204

def resolve_references
  if context_reference
    # Looking up references to questions and answers for linking the dependency objects
    print (self.question = context_reference[:question_references][question_reference]) ? "found question:#{question_reference} " : "lost! question:#{question_reference} "
    context_reference[:answer_references][question_reference] ||= {}
    print (self.answer = context_reference[:answer_references][question_reference][answer_reference]) ? "found answer:#{answer_reference} " : "lost! answer:#{answer_reference} "
  end
end

- (Object) unparse(dsl)

nonblock



95
96
97
98
99
100
101
102
# File 'lib/surveyor/unparser.rb', line 95

def unparse(dsl)
  attrs = (self.attributes.diff Dependency.new.attributes).delete_if{|k,v| %w(created_at updated_at question_id question_group_id rule_key rule operator id dependency_id answer_id).include? k}.symbolize_keys!
  dsl << "  " if dependency.question.part_of_group?
  dsl << "    condition"
  dsl << "_#{rule_key}" unless rule_key.blank?
  dsl << " :q_#{question.reference_identifier}, \"#{operator}\""
  dsl << (attrs.blank? ? ", {:answer_reference=>\"#{answer && answer.reference_identifier}\"}\n" : ", {#{attrs.inspect.gsub(/\{|\}/, "")}, :answer_reference=>\"#{answer && answer.reference_identifier}\"}\n")
end