Class: Validation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Validation
- Defined in:
- app/models/validation.rb
Instance Method Summary collapse
-
#conditions_hash(response_set) ⇒ Object
A hash of the conditions (keyed by rule_key) and their evaluation (boolean) in the context of response_set.
-
#is_valid?(response_set) ⇒ Boolean
Instance Methods.
Instance Method Details
#conditions_hash(response_set) ⇒ Object
A hash of the conditions (keyed by rule_key) and their evaluation (boolean) in the context of response_set
31 32 33 34 35 36 37 |
# File 'app/models/validation.rb', line 31 def conditions_hash(response_set) hash = {} response = response_set.responses.detect{|r| r.answer_id.to_i == self.answer_id.to_i} # logger.debug "r: #{response.inspect}" self.validation_conditions.each{|vc| hash.merge!(vc.to_hash(response))} return hash end |
#is_valid?(response_set) ⇒ Boolean
Instance Methods
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/validation.rb', line 19 def is_valid?(response_set) ch = conditions_hash(response_set) rgx = Regexp.new(self.validation_conditions.map{|vc| ["a","o"].include?(vc.rule_key) ? "#{vc.rule_key}(?!nd|r)" : vc.rule_key}.join("|")) # exclude and, or # logger.debug "v: #{self.inspect}" # logger.debug "rule: #{self.rule.inspect}" # logger.debug "rexp: #{rgx.inspect}" # logger.debug "keyp: #{ch.inspect}" # logger.debug "subd: #{self.rule.gsub(rgx){|m| ch[m.to_sym]}}" eval(self.rule.gsub(rgx){|m| ch[m.to_sym]}) end |