Module: Surveyor::Models::SurveySectionMethods

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::ForbiddenAttributesProtection, ActiveModel::Validations
Included in:
SurveySection
Defined in:
lib/surveyor/models/survey_section_methods.rb

Instance Method Summary collapse

Instance Method Details

#default_argsObject



24
25
26
# File 'lib/surveyor/models/survey_section_methods.rb', line 24

def default_args
  self.data_export_identifier ||= Surveyor::Common.normalize(title)
end

#initialize(*args) ⇒ Object

Instance Methods



19
20
21
22
# File 'lib/surveyor/models/survey_section_methods.rb', line 19

def initialize(*args)
  super(*args)
  default_args
end

#questions_and_groupsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/surveyor/models/survey_section_methods.rb', line 28

def questions_and_groups
  qs = []
  questions.each_with_index.map do |q,i|
    if q.part_of_group?
      if (i+1 >= questions.size) or (q.question_group_id != questions[i+1].question_group_id)
        q.question_group
      end
    else
      q
    end
  end.compact
end

#translation(locale) ⇒ Object



41
42
43
44
45
# File 'lib/surveyor/models/survey_section_methods.rb', line 41

def translation(locale)
  {:title => self.title, :description => self.description}.with_indifferent_access.merge(
    (self.survey.translation(locale)[:survey_sections] || {})[self.reference_identifier] || {}
  )
end