Quizzy

Quizzy is a declarative survey engine that given a survey definition will render pages from the survey and perform validation and routing on submits of survey pages.

A very simple survey definition might look like:

{
  :pages =>
    [
      { :questions => [{ :template => "radio", :name => "test" }] },
      { :questions => [{ :template => "checkbox", :name => "cbox" }] }
    ],
  :question_templates => {
    :radio => %q{<input type="radio" name="{{name}}" value="1">},
    :checkbox => %q{<input type="checkbox" name="{{name}}">}
  }
}

This definition has two pages, one with a radio button and one with a checkbox. As shown a question hash is something like:

{ :template => "radio", :name => "test" }

The questions are rendered with the question_template named in the template key in the question hash. Any other attributes are passed to the question template on rendering (like name in the above example).

Please see doc/survey_definition.rdoc for further information.

Validations

Validations are added to pages and will be run when the page is submitted. A page with a validation could look like:

{ :questions => { :template => "radio", :name => "test" },
  :validations =>
    [{ :eval    => "response[:test] == '1'",
       :message => "Please pick a radio" }]
}

Given a response it is possible to ask if a page is valid for the response. In the above example the page is only valid for responses where test is set to 1.

Branching

By default users will be routed through the survey in the order of the pages. It is possible to setup routing rules and ask the engine to route the respondent other ways through. This is usually used for skipping pages that are not relevant for a given respondent.

A survey definition with branching rules could look like:

{ :pages => [
    { :questions => [{:template => :radio, :name => "test" }],
      :postbranches => [{:eval => "response[:test] == '1'",
                         :redirect_to => :page3 }]
    },
    { :questions => [{:template => :radio, :name => "test2"}]},
    { :id => :page3,
      :questions => [{:template => :radio, :name => "test3"}]}
]}

In this case the respondent will go directly to page 3 if the response contains test = 1, otherwise the respondent will go to page 2. Notice the match between the redirect_to key in the postbranch and the id on page 3.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Jacob Atzen. See LICENSE for details.