Class SmerfItem
In: app/models/smerf_item.rb
Parent: Object

SmerfItem class is a base class used by all other smerf classes and contains shared functionality.

Derived classes include:

Methods

Attributes

code_unique_for_smerf  [RW]  Specifies that the codes for sub items (e.g. questions) must be unique for the complete form, if this is false then we check only within this item (e.g. answer codes for a question)
object_ident  [RW]  The object_id is unique id for all objects contructed by taking the owner_ident and combining it with this objects code. For example: group code 1, object id would be practiceprofile~~1, questions for this group might have object id practiceprofile~~1~~g1q1
owner_ident  [RW]  This is the id of the object that owns this one, nil means that we have reached the root object, normally the smerffile object. Keeping this information allows us to walk the object tree to find owners.

Public Class methods

Public Instance methods

This method reloads all our class variables after the form is unserialized from the DB. As the class variables are not serialized and holds references to objects we need to load these once all objects have been created.

Protected Instance methods

This is a small helper method that checks the errors string to see if there are any errors present, if so we raise an exception

This method decodes the raw data read in from a YAML file. When defining a new section/level in a YAML file you do so by specifying a section/level header, e.g. groups:, but there is no value associated with it, sub items are then defined, i.e. code: xyz. When the YAML file is loaded the header is loaded into an element array with 0 as the index and the items for the level is loaded into another element with 1 as the index.

The method takes a hash, a field name and an error message. The method checks the hash to see if the field exists, it also checks to see if a value has been specified for the field. If not the supplied error message or if a empty string was supplied for the msg param then a default error will be returned.

For each form item a list of fields that can be used in the YAML file to define the item is defined (see SmerfGroup for example). This method is called to firstly setup a hash that contains all the fields, it checks that the sort order field is present and then checks the other fields. When setting up the fields you can specify if the field is mandatory or requires further validation.

This method takes a class name (SmerfGroup), a hash that contains the data read in from the YAML file, the order in which these sub items should be sorted and array in which to return the objects created for each sub item.

This function validates sub items such as groups, questions, etc. It creates and object of the specified class and performs the validation on the contents for each item in the specified hash.

For example the smerffile object passes the groups array to this function, this function creates a SmerfGroup object for each item in the array. It then performs validation for each group and adds it to the object array which is then used in the Smerf object. The same thing happens for the questions defined in each group, we create an SmerfQuestion object for each item passed in the array by the SmerfGroup object.

[Validate]