Module SmerfSystemHelpers
In: lib/smerf_system_helpers.rb

This module contains some standard helper methods used by smerf.

All validation methods need to take three parameters:

question:The SmerfQuestion object to be validated
responses:Hash containing user responses keyed using the question code
form:Hash that contains all form objects including groups, questions and answers

The method needs to return an empty string or nil if no errors or if there is an error then an error message describing the error should be returned.

Within the form definition file you specify if a validation is required on a question by specifying which methods within this module should be called to perform that validation, e.g.


  code: g1q1
  type: singlechoice
  sort_order: 1
  question: | Specify your ages
  help: | Select the <b>one</b> that apply
  validation: validation_mandatory

Multiple validation methods can be specified by comma separating each method name.


Public Instance methods

This method will find the object with the specified object ident

This method will find the owner object of the object passed in as a parameter

This method retrieves the answer to the supplied question, if no answer found it will return nil. This method may return a hash containing all answers if the question allows multiple choices.

This method check the to see if the supplied question has been answered

This method will check if the question has the answer passed as a parameter. Some questions allow multiple answers so we need to check if one of the answers is equal to the supplied answer.

This method checks to make sure that mandatory questions have been answered by the user

This method will perform two checks:

  1. Check if the subquestion has been answered, if so then we want to make sure that the answer this subquestion relates to has been answered
  2. If the answer that has a subquestion is answered then make sure the subquestion has been answered

This validation method is called from a subquestion, so the object parameter should be a subquestion