Module: Surveyor::Models::AnswerMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::ForbiddenAttributesProtection, ActiveModel::Validations, Surveyor::MustacheContext
- Included in:
- Answer
- Defined in:
- lib/surveyor/models/answer_methods.rb
Instance Method Summary collapse
- #css_class ⇒ Object
- #default_args ⇒ Object
- #default_value_for(context = nil, locale = nil) ⇒ Object
- #display_type=(val) ⇒ Object
- #help_text_for(context = nil, locale = nil) ⇒ Object
-
#initialize(*args) ⇒ Object
Instance Methods.
- #split(text, position = nil) ⇒ Object
- #text_for(position = nil, context = nil, locale = nil) ⇒ Object
- #translation(locale) ⇒ Object
Methods included from Surveyor::MustacheContext
Instance Method Details
#css_class ⇒ Object
39 40 41 |
# File 'lib/surveyor/models/answer_methods.rb', line 39 def css_class [(is_exclusive ? "exclusive" : nil), custom_class].compact.join(" ") end |
#default_args ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/surveyor/models/answer_methods.rb', line 27 def default_args self.is_exclusive ||= false self.display_type ||= "default" self.response_class ||= "answer" self.short_text ||= text self.data_export_identifier ||= Surveyor::Common.normalize(text) self.api_id ||= Surveyor::Common.generate_api_id end |
#default_value_for(context = nil, locale = nil) ⇒ Object
50 51 52 |
# File 'lib/surveyor/models/answer_methods.rb', line 50 def default_value_for(context = nil, locale = nil) in_context(translation(locale)[:default_value], context) end |
#display_type=(val) ⇒ Object
35 36 37 |
# File 'lib/surveyor/models/answer_methods.rb', line 35 def display_type=(val) write_attribute(:display_type, val.nil? ? nil : val.to_s) end |
#help_text_for(context = nil, locale = nil) ⇒ Object
47 48 49 |
# File 'lib/surveyor/models/answer_methods.rb', line 47 def help_text_for(context = nil, locale = nil) in_context(translation(locale)[:help_text], context) end |
#initialize(*args) ⇒ Object
Instance Methods
22 23 24 25 |
# File 'lib/surveyor/models/answer_methods.rb', line 22 def initialize(*args) super(*args) default_args end |
#split(text, position = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/surveyor/models/answer_methods.rb', line 53 def split(text, position=nil) case position when :pre text.split("|",2)[0] when :post text.split("|",2)[1] else text end.to_s end |
#text_for(position = nil, context = nil, locale = nil) ⇒ Object
43 44 45 46 |
# File 'lib/surveyor/models/answer_methods.rb', line 43 def text_for(position = nil, context = nil, locale = nil) return "" if display_type == "hidden_label" imaged(split(in_context(translation(locale)[:text], context), position)) end |
#translation(locale) ⇒ Object
63 64 65 66 67 |
# File 'lib/surveyor/models/answer_methods.rb', line 63 def translation(locale) {:text => self.text, :help_text => self.help_text, :default_value => self.default_value}.with_indifferent_access.merge( (self.question.translation(locale)[:answers] || {})[self.reference_identifier] || {} ) end |