Class: Missinglink::SurveyQuestion
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Missinglink::SurveyQuestion
- Defined in:
- app/models/missinglink/survey_question.rb
Class Method Summary collapse
Class Method Details
.first_or_create_by_sm_id(sm_id) ⇒ Object
27 28 29 30 31 32 33 |
# File 'app/models/missinglink/survey_question.rb', line 27 def self.first_or_create_by_sm_id(sm_id) if question = SurveyQuestion.find_by_sm_question_id(sm_id) return question else return SurveyQuestion.create(sm_question_id: sm_id) end end |
.parse(page, hash) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/missinglink/survey_question.rb', line 10 def self.parse(page, hash) question = SurveyQuestion.first_or_create_by_sm_id(hash['question_id']) question.update_attributes({ heading: hash['heading'], position: hash['position'].to_i, type_family: hash['type']['family'], type_subtype: hash['type']['subtype'] }) question.survey_pages = [page] question.save hash['answers'].each do |answer| SurveyAnswer.parse(question, answer) end return question.reload end |