Module: Surveyor::Models::AnswerMethods
- Included in:
- Answer
- Defined in:
- lib/surveyor/models/answer_methods.rb
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) css_class
- - (Object) default_args
-
- (AnswerMethods) initialize(*args)
Instance Methods.
- - (Object) split_or_hidden_text(part = nil)
Class Method Details
+ (Object) included(base)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/surveyor/models/answer_methods.rb', line 6 def self.included(base) # Associations base.send :belongs_to, :question base.send :has_many, :responses base.send :has_many, :validations, :dependent => :destroy # Scopes base.send :default_scope, :order => "display_order ASC" @@validations_already_included ||= nil unless @@validations_already_included # Validations base.send :validates_presence_of, :text # this causes issues with building and saving # base.send :validates_numericality_of, :question_id, :allow_nil => false, :only_integer => true @@validations_already_included = true end end |
Instance Method Details
- (Object) css_class
41 42 43 |
# File 'lib/surveyor/models/answer_methods.rb', line 41 def css_class [(is_exclusive ? "exclusive" : nil), custom_class].compact.join(" ") end |
- (Object) default_args
31 32 33 34 35 36 37 38 39 |
# File 'lib/surveyor/models/answer_methods.rb', line 31 def default_args self.display_order ||= self.question ? self.question.answers.count : 0 self.is_exclusive ||= false self.hide_label ||= false self.response_class ||= "answer" self.short_text ||= text self.data_export_identifier ||= Surveyor::Common.normalize(text) self.api_id ||= UUID.generate end |
- (AnswerMethods) initialize(*args)
Instance Methods
26 27 28 29 |
# File 'lib/surveyor/models/answer_methods.rb', line 26 def initialize(*args) super(*args) default_args end |
- (Object) split_or_hidden_text(part = nil)
45 46 47 48 |
# File 'lib/surveyor/models/answer_methods.rb', line 45 def split_or_hidden_text(part = nil) return "" if hide_label.to_s == "true" part == :pre ? text.split("|",2)[0] : (part == :post ? text.split("|",2)[1] : text) end |