Sha256: 406ad68ffe16b199aee60dae3f84d06195f535b605ade9a64ea35bea1f51afb3

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module SurveySays
  module ActsAsSurveySays
    extend ActiveSupport::Concern

    included do
    end

    module ClassMethods
      def acts_as_survey_says(options = {})
        # your code will go here
      end
    end

    def add_answers(ids)
      self.answer_ids = answer_ids | ids
      self.save
    end

    def score_user!
      score_answer_ids = user_answers.map(&:answer_id)
      Score.group(:survey_property_id).
            select("scores.*, SUM(scores.value) as value, survey_properties.name").
            joins(:survey_property).
            where(['scores.answer_id IN (?)',score_answer_ids]).all
    end
    def score_questionnaire(questionnaire_id)
      questionnaire = Questionnaire.includes({:questions => :answers}).find(questionnaire_id)
      score_answer_ids = questionnaire.questions.map(&:answer_ids).flatten & answer_ids
      Score.group(:survey_property_id).
            select("scores.*, SUM(scores.value) as value, survey_properties.name").
            joins(:survey_property).
            where(['scores.answer_id IN (?)',score_answer_ids]).all
    end
  end
end

ActiveRecord::Base.send :include, SurveySays::ActsAsSurveySays

=begin

module SurveySays
  module ActsAsSurveySays
    extend ActiveSupport::Concern

    included do
    end

    module ClassMethods
      def acts_as_survey_says(options = {})
        # your code will go here
      end
    end
  end
end

ActiveRecord::Base.send :include, Yaffle::ActsAsSurveySays

=end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
survey_says-0.0.2 lib/survey_says/acts_as_survey_says.rb
survey_says-0.0.1 lib/survey_says/acts_as_survey_says.rb