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
- #css_class(response_set) ⇒ Object
- #default_args ⇒ Object
- #dependent? ⇒ Boolean
- #display_type=(val) ⇒ Object
- #help_text_for(context = nil, locale = nil) ⇒ Object
-
#initialize(*args) ⇒ Object
Instance Methods.
- #renderer ⇒ Object
- #text_for(context = nil, locale = nil) ⇒ Object
- #translation(locale) ⇒ Object
- #triggered?(response_set) ⇒ Boolean
Methods included from Surveyor::MustacheContext
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_args ⇒ Object
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
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 |
#renderer ⇒ Object
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
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 |