Module: Surveyor::Models::QuestionGroupMethods

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RenderText

#render_answer_text, #render_help_text, #render_question_text, #render_text

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

#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

#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