Sha256: 7b84251c0b31a81df5935f8adb6644c21e24a2d0fe80f86e79d72f7dc1a2af25

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

module Surveyor
  module Models
    module ResponseMethods
      def self.included(base)
        # Associations
        base.send :belongs_to, :response_set
        base.send :belongs_to, :question
        base.send :belongs_to, :answer

        # Validations
        base.send :validates_presence_of, :response_set_id, :question_id, :answer_id

        base.send :include, Surveyor::ActsAsResponse # includes "as" instance method

      end

      # Instance Methods
      def selected
        !self.new_record?
      end

      alias_method :selected?, :selected

      def selected=(value)
        true
      end

      def correct?
        question.correct_answer_id.nil? or self.answer.response_class != "answer" or (question.correct_answer_id.to_i == answer_id.to_i)
      end

      def to_s # used in dependency_explanation_helper
        if self.answer.response_class == "answer" and self.answer_id
          return self.answer.text
        else
          return "#{(self.string_value || self.text_value || self.integer_value || self.float_value || nil).to_s}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
surveyor-0.18.0 lib/surveyor/models/response_methods.rb
surveyor-0.17.0 lib/surveyor/models/response_methods.rb
surveyor-0.16.1 lib/surveyor/models/response_methods.rb
surveyor-0.16.0 lib/surveyor/models/response_methods.rb
surveyor-0.15.0 lib/surveyor/models/response_methods.rb