Class: Missinglink::SurveyRespondentDetail
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Missinglink::SurveyRespondentDetail
- Defined in:
- app/models/missinglink/survey_respondent_detail.rb
Class Method Summary collapse
- .first_or_create_by_survey_details(survey_id, sm_id) ⇒ Object
- .parse(survey, hash) ⇒ Object
- .prepare_respondent_details(respondent_hash) ⇒ Object
Instance Method Summary collapse
Class Method Details
.first_or_create_by_survey_details(survey_id, sm_id) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'app/models/missinglink/survey_respondent_detail.rb', line 20 def self.first_or_create_by_survey_details(survey_id, sm_id) # spelling this one out more explicitly so it's easier to test if new_srd = SurveyRespondentDetail.find_by_survey_id_and_sm_respondent_id(survey_id, sm_id.to_i) return new_srd else return SurveyRespondentDetail.create(survey_id: survey_id, sm_respondent_id: sm_id.to_i) end end |
.parse(survey, hash) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/models/missinglink/survey_respondent_detail.rb', line 11 def self.parse(survey, hash) srd = SurveyRespondentDetail.first_or_create_by_survey_details(survey.id, hash['respondent_id']) attrs = prepare_respondent_details(hash) srd.update_attributes(attrs) return srd end |
.prepare_respondent_details(respondent_hash) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/missinglink/survey_respondent_detail.rb', line 67 def self.prepare_respondent_details(respondent_hash) hash = { collection_mode: respondent_hash['collection_mode'], custom_id: respondent_hash['custom_id'], email: respondent_hash['email'], first_name: respondent_hash['first_name'], last_name: respondent_hash['last_name'], ip_address: respondent_hash['ip_address'], status: respondent_hash['status'] || "completed", analysis_url: respondent_hash['analysis_url'] } (hash[:date_start] = Date.parse(respondent_hash['date_start'])) if respondent_hash['date_start'] (hash[:date_modified] = Date.parse(respondent_hash['date_modified'])) if respondent_hash['date_modified'] (hash[:collector_id] = respondent_hash['collector_id'].to_i) if respondent_hash['collector_id'] return hash end |
Instance Method Details
#response_to_question(question) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/missinglink/survey_respondent_detail.rb', line 29 def response_to_question(question) return nil unless response = survey_responses.find_by_survey_question_id(question.id) response_texts = [] case question.answer_strategy when "first_survey_response_answer_text" return response.survey_response_answers.first.text when "answer_row_for_response" response.survey_response_answers.each do |sra| if sra.text.nil? response_texts << SurveyAnswer.find(sra.row_survey_answer_id).text else response_texts << (SurveyAnswer.find(sra.row_survey_answer_id).text + ": " + sra.text) end end when "answer_row_and_column_for_response" response.survey_response_answers.each do |sra| if sra.text.nil? response_texts << (SurveyAnswer.find(sra.row_survey_answer_id).text + ": " + SurveyAnswer.find(sra.col_survey_answer_id).text) else response_texts << "Other: #{ sra.text }" end end when "answer_row_column_choice_for_response" response.survey_response_answers.each do |sra| if sra.text.nil? response_texts << (SurveyAnswer.find(sra.row_survey_answer_id).text + ", " + SurveyAnswer.find(sra.col_survey_answer_id).text + ": " + SurveyAnswer.find(sra.col_choice_survey_answer_id).text) else response_texts << "Other: #{ sra.text }" end end end return response_texts.join("; ") end |