Class: Missinglink::SurveyResponse
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Missinglink::SurveyResponse
- Defined in:
- app/models/missinglink/survey_response.rb
Class Method Summary collapse
- .first_or_create_by_respondent_and_question(respondent_id, question_id) ⇒ Object
- .parse(survey, hash) ⇒ Object
Class Method Details
.first_or_create_by_respondent_and_question(respondent_id, question_id) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/missinglink/survey_response.rb', line 20 def self.first_or_create_by_respondent_and_question(respondent_id, question_id) if new_response = SurveyResponse.find_by_survey_respondent_detail_id_and_survey_question_id(respondent_id.to_i, question_id.to_i) return new_response else return SurveyResponse.create(survey_respondent_detail_id: respondent_id.to_i, survey_question_id: question_id.to_i) end end |
.parse(survey, hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'app/models/missinglink/survey_response.rb', line 9 def self.parse(survey, hash) respondent = SurveyRespondentDetail.find_by_sm_respondent_id(hash['respondent_id'].to_i) hash['questions'].each do |question_hash| question = SurveyQuestion.find_by_sm_question_id(question_hash['question_id']) response = SurveyResponse.first_or_create_by_respondent_and_question(respondent.id, question.id) question_hash['answers'].each do |answer_hash| SurveyResponseAnswer.parse(response, answer_hash) end end end |