Module: SurveyorParserAnswerMethods
- Defined in:
- lib/surveyor/parser.rb
Overview
Answer model
Instance Method Summary collapse
- #hash_from(arg) ⇒ Object
- #parse_and_build(context, args, original_method, reference_identifier) ⇒ Object
- #parse_args(args) ⇒ Object
- #symbol_args(arg) ⇒ Object
- #text_args(text = "Answer") ⇒ Object
Instance Method Details
#hash_from(arg) ⇒ Object
362 363 364 |
# File 'lib/surveyor/parser.rb', line 362 def hash_from(arg) arg.is_a?(Symbol) ? {:response_class => arg.to_s} : arg.is_a?(Hash) ? arg : {} end |
#parse_and_build(context, args, original_method, reference_identifier) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/surveyor/parser.rb', line 325 def parse_and_build(context, args, original_method, reference_identifier) # clear context [ :answer, :validation, :validation_condition ].each{|k| context.delete k} attrs = { :reference_identifier => reference_identifier }.merge(parse_args(args)) # add answers to grid if context[:question_group] && context[:question_group].display_type == "grid" self.attributes = ({:display_order => context[:grid_answers].size}.merge(attrs)) context[:grid_answers] << context[:answer] = self else self.attributes = ({:display_order => context[:question].answers.size}.merge(attrs)) context[:question].answers << context[:answer] = self # keep reference for dependencies unless context[:question].reference_identifier.blank? or reference_identifier.blank? context[:answer_references][context[:question].reference_identifier] ||= {} context[:duplicate_references].push "q_#{context[:question].reference_identifier}, a_#{reference_identifier}" if context[:answer_references][context[:question].reference_identifier].has_key?(reference_identifier) context[:answer_references][context[:question].reference_identifier][reference_identifier] = context[:answer] end end end |
#parse_args(args) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/surveyor/parser.rb', line 347 def parse_args(args) case args[0] when Hash # Hash text_args(args[0][:text]).merge(args[0]) when String # (String, Hash) or (String, Symbol, Hash) text_args(args[0]).merge(hash_from args[1]).merge(args[2] || {}) when Symbol # (Symbol, Hash) or (Symbol, Symbol, Hash) symbol_args(args[0]).merge(hash_from args[1]).merge(args[2] || {}) else text_args(nil) end end |
#symbol_args(arg) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/surveyor/parser.rb', line 365 def symbol_args(arg) case arg when :other text_args("Other") when :other_and_string text_args("Other").merge({:response_class => "string"}) when :none, :omit # is_exclusive erases and disables other checkboxes and input elements text_args(arg.to_s.humanize).merge({:is_exclusive => true}) when :integer, :float, :date, :time, :datetime, :text, :datetime, :string text_args(arg.to_s.humanize).merge({:response_class => arg.to_s, :display_type => "hidden_label"}) end end |
#text_args(text = "Answer") ⇒ Object
359 360 361 |
# File 'lib/surveyor/parser.rb', line 359 def text_args(text = "Answer") {:text => text.to_s} end |