Class: Missinglink::SurveyResponseAnswer

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/missinglink/survey_response_answer.rb

Class Method Summary collapse

Class Method Details

.parse(response, hash) ⇒ Object



7
8
9
10
11
12
# File 'app/models/missinglink/survey_response_answer.rb', line 7

def self.parse(response, hash)
  answer = SurveyResponseAnswer.create({survey_response_id: response.id}.
                                          merge(prepare_answer_hash(hash)))

  return answer
end

.prepare_answer_hash(hash) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'app/models/missinglink/survey_response_answer.rb', line 15

def self.prepare_answer_hash(hash)
  clean_hash = {}
  clean_hash['row_survey_answer_id'] = SurveyAnswer.find_by_sm_answer_id(hash['row'].to_i).id if (hash['row'] && hash['row'] != "0")
  clean_hash['col_survey_answer_id'] = SurveyAnswer.find_by_sm_answer_id(hash['col'].to_i).id if hash['col']
  clean_hash['col_choice_survey_answer_id'] = SurveyAnswer.find_by_sm_answer_id(hash['col_choice'].to_i).id if hash['col_choice']
  clean_hash['text'] = hash['text'] if hash['text']

  return clean_hash
end