Module: Surveyor::Models::QuestionGroupMethods

Includes:
Surveyor::MustacheContext
Included in:
QuestionGroup
Defined in:
lib/surveyor/models/question_group_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Surveyor::MustacheContext

#in_context

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/surveyor/models/question_group_methods.rb', line 6

def self.included(base)
  # Associations
  base.send :has_many, :questions
  base.send :has_one, :dependency

  # Whitelisting attributes
  base.send :attr_accessible, :text, :help_text, :reference_identifier, :data_export_identifier, :common_namespace, :common_identifier, :display_type, :custom_class, :custom_renderer
end

Instance Method Details

#css_class(response_set) ⇒ Object



42
43
44
# File 'lib/surveyor/models/question_group_methods.rb', line 42

def css_class(response_set)
  [(dependent? ? "g_dependent" : nil), (triggered?(response_set) ? nil : "g_hidden"), custom_class].compact.join(" ")
end

#default_argsObject



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

def default_args
  self.display_type ||= "inline"
  self.api_id ||= Surveyor::Common.generate_api_id
end

#dependent?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/surveyor/models/question_group_methods.rb', line 36

def dependent?
  self.dependency != nil
end

#display_type=(val) ⇒ Object



32
33
34
# File 'lib/surveyor/models/question_group_methods.rb', line 32

def display_type=(val)
  write_attribute(:display_type, val.nil? ? nil : val.to_s)
end

#help_text_for(context = nil, locale = nil) ⇒ Object



50
51
52
# File 'lib/surveyor/models/question_group_methods.rb', line 50

def help_text_for(context = nil, locale = nil)
  in_context(translation(locale)[:help_text], context)
end

#initialize(*args) ⇒ Object

Instance Methods



18
19
20
21
# File 'lib/surveyor/models/question_group_methods.rb', line 18

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

#rendererObject



28
29
30
# File 'lib/surveyor/models/question_group_methods.rb', line 28

def renderer
  display_type.blank? ? :default : display_type.to_sym
end

#text_for(context = nil, locale = nil) ⇒ Object



46
47
48
49
# File 'lib/surveyor/models/question_group_methods.rb', line 46

def text_for(context = nil, locale = nil)
  return "" if display_type == "hidden_label"
  in_context(translation(locale)[:text], context)
end

#translation(locale) ⇒ Object



54
55
56
57
58
# File 'lib/surveyor/models/question_group_methods.rb', line 54

def translation(locale)
  {:text => self.text, :help_text => self.help_text}.with_indifferent_access.merge(
    (self.questions.first.survey_section.survey.translation(locale)[:question_groups] || {})[self.reference_identifier] || {}
  )
end

#triggered?(response_set) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/surveyor/models/question_group_methods.rb', line 39

def triggered?(response_set)
  dependent? ? self.dependency.is_met?(response_set) : true
end