Module: Surveyor::Models::ValidationConditionMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::ForbiddenAttributesProtection, ActiveModel::Validations, ActsAsResponse
- Included in:
- ValidationCondition
- Defined in:
- lib/surveyor/models/validation_condition_methods.rb
Instance Method Summary collapse
- #is_valid?(response) ⇒ Boolean
-
#to_hash(response) ⇒ Object
Instance Methods.
Methods included from ActsAsResponse
Instance Method Details
#is_valid?(response) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/surveyor/models/validation_condition_methods.rb', line 25 def is_valid?(response) klass = response.answer.response_class compare_to = Response.find_by_question_id_and_answer_id(self.question_id, self.answer_id) || self case self.operator when "==", "<", ">", "<=", ">=" response.as(klass).send(self.operator, compare_to.as(klass)) when "!=" !(response.as(klass) == compare_to.as(klass)) when "=~" return false if compare_to != self !(response.as(klass).to_s =~ Regexp.new(self.regexp || "")).nil? else false end end |
#to_hash(response) ⇒ Object
Instance Methods
21 22 23 |
# File 'lib/surveyor/models/validation_condition_methods.rb', line 21 def to_hash(response) {rule_key.to_sym => (response.nil? ? false : self.is_valid?(response))} end |