Module: Surveyor::Models::QuestionGroupMethods

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::ForbiddenAttributesProtection, ActiveModel::Validations, Surveyor::MustacheContext
Included in:
QuestionGroup
Defined in:
lib/surveyor/models/question_group_methods.rb

Instance Method Summary collapse

Methods included from Surveyor::MustacheContext

#in_context

Instance Method Details

#css_class(response_set) ⇒ Object



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

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

#default_argsObject



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

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

#dependent?Boolean

Returns:

  • (Boolean)


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

def dependent?
  self.dependency != nil
end

#display_type=(val) ⇒ Object



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

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

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



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

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

#initialize(*args) ⇒ Object

Instance Methods



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

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

#rendererObject



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

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

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



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

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

#translation(locale) ⇒ Object



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

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)


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

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