Module: Reporter::Record::Question

Defined in:
lib/reporter/record/question.rb,
lib/reporter/record/question/base.rb,
lib/reporter/record/question/single.rb,
lib/reporter/record/question/placeholder.rb

Overview

Namespace module for classes representing Reporter questions.

Defined Under Namespace

Classes: Base, Placeholder, Single

Class Method Summary collapse

Class Method Details

.factory(data) ⇒ Object

Public: Create a Question subclass from the raw data.

This method analyzes the data structure, and instantiates the correct subclass for the provided data.

data - The Hash of data contained in the Question.

Examples

Reporter::Record::Question.factory({
  "prompt" => "Foo bar baz?",
  "placeholderString" => "Placeholder answer",
})
=> #<Reporter::Record::Question::Placeholder>

23
24
25
26
27
28
29
30
31
32
33
# File 'lib/reporter/record/question.rb', line 23

def self.factory(data)
  klass = if data.has_key? "placeholderString"
            Reporter::Record::Question::Placeholder
          elsif data["allowMultipleSelection"].to_s == "0"
            Reporter::Record::Question::Single
          else
            Reporter::Record::Question::Base
          end

  klass.new data
end