Class: Answer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Answer
- 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
-
#unparse(dsl) ⇒ Object
nonblock.
Methods included from Surveyor::Models::AnswerMethods
#css_class, #default_args, #default_value_for, #display_type=, #help_text_for, #initialize, #split, #text_for, #translation
Methods included from Surveyor::MustacheContext
Instance Method Details
#unparse(dsl) ⇒ Object
nonblock
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/surveyor/unparser.rb', line 118 def unparse(dsl) with_defaults = Answer.new(:text => text) attrs = self.attributes.delete_if{|k,v| with_defaults[k] == v or %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 |