Class: Answer

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Surveyor::Models::AnswerMethods
Defined in:
app/models/answer.rb,
lib/surveyor/unparser.rb,
lib/generators/surveyor/templates/db/migrate/update_blank_api_ids_on_question_group.rb

Instance Method Summary collapse

Methods included from Surveyor::Models::AnswerMethods

#css_class, #default_args, #default_value_for, #display_type=, #help_text_for, included, #initialize, #split, #text_for, #translation

Instance Method Details

#unparse(dsl) ⇒ Object

nonblock



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/surveyor/unparser.rb', line 107

def unparse(dsl)
  attrs = (self.attributes.diff Answer.new(:text => text).attributes).delete_if{|k,v| %w(created_at updated_at reference_identifier response_class id question_id api_id).include? k}.symbolize_keys!
  attrs.delete(:is_exclusive) if text == "Omit" && is_exclusive == true
  attrs.merge!({:is_exclusive => false}) if text == "Omit" && is_exclusive == false
  dsl << "  " if question.part_of_group?
  dsl << "    a"
  dsl << "_#{reference_identifier}" unless reference_identifier.blank?
  if response_class.to_s.titlecase == text && attrs == {:display_type => "hidden_label"}
    dsl << " :#{response_class}"
  else    
    dsl << [ text.blank? ? nil : text == "Other" ? " :other" : text == "Omit" ? " :omit" : " \"#{text}\"",
              (response_class.blank? or response_class == "answer") ? nil : " #{response_class.to_sym.inspect}",
              attrs.blank? ? nil : " #{attrs.inspect.gsub(/\{|\}/, "")}\n"].compact.join(",")
  end
  dsl << "\n"
  validations.each{|validation| validation.unparse(dsl)}
end