Class: SurveySection

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Surveyor::Models::SurveySectionMethods
Defined in:
lib/surveyor/unparser.rb,
app/models/survey_section.rb

Instance Method Summary collapse

Methods included from Surveyor::Models::SurveySectionMethods

#default_args, included, #initialize, #questions_and_groups, #translation

Instance Method Details

#unparse(dsl) ⇒ Object

block



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/surveyor/unparser.rb', line 27

def unparse(dsl)
  attrs = (self.attributes.diff SurveySection.new(:title => title).attributes).delete_if{|k,v| %w(created_at updated_at id survey_id).include? k}.symbolize_keys!
  group_questions = []
  dsl << "  section \"#{title}\""
  dsl << (attrs.blank? ? " do\n" : ", #{attrs.inspect.gsub(/\{|\}/, "")} do\n")
  questions.each_with_index do |question, index|
    if question.solo?
      question.unparse(dsl)
    else # gather up the group questions
      group_questions << question
      if (index + 1 >= questions.size) or (question.question_group != questions[index + 1].question_group)
        # this is the last question of the section, or the group
        question.question_group.unparse(dsl)
      end
      group_questions = []
    end
  end
  dsl << "  end\n"
end