Class SmerfAnswer
In: app/models/smerf_answer.rb
Parent: SmerfItem

This class contains details about answers to form questions, it derives from SmerfItem.

It knows how to handle subquestions. Subquestions are additional questions that a user can answer if certain answers are selected. An example subquestion would be where an Other is provided as one of the answers to a question, a subquestion can be defined to display a text field to accept more information.

Question answers are defined using the following fields:

code:Code to uniquely identify the answer, code needs to be unique for each question (mandatory). The value specified here will be saved as the users response when the answer is selected.
answer:The text that will be displayed to the user (mandatory)
default:If set to Y then this answer will be selected by default (optional)
sort_order:The sort order for this answer (mandatory)
subquestions:Some answers may need additional information, another question can be defined to obtain this information. To define a subquestion the same fields that define a normal question is used (optional)

Here is an example answer definition:

     answers:
       1_20:
         code: 1
         answer: | 1-20
         sort_order: 1
         default: N
         ...

Methods

clear   new   validate  

Attributes

answer  [RW] 
code  [RW] 
default  [RW] 
sort_order  [RW] 
subquestion_objects  [RW] 

Public Class methods

Clear all class variables

Public Instance methods

This method performs the bulk of the processing. It processes the answer definition making sure that all mandatory fields have values. If any subquestions are found they will be processed and validated. Subquestions are treated as normal questions and processed by the SmerfQuestion class.

As it processes the data it also performs validation on the data to make sure all required fields have been specified in the definition file. If any errors are found a RuntimeError exception will be raised.

[Validate]