Module: Reporter::Record::Response

Defined in:
lib/reporter/record/response.rb,
lib/reporter/record/response/note.rb,
lib/reporter/record/response/base.rb,
lib/reporter/record/response/token.rb,
lib/reporter/record/response/numeric.rb,
lib/reporter/record/response/location.rb,
lib/reporter/record/response/multiple_choice.rb

Overview

Namespace module for classes representing responses to Reporter

questions.

Defined Under Namespace

Modules: BaseModule Classes: Base, Location, MultipleChoice, Note, Numeric, Token

Class Method Summary collapse

Class Method Details

.factory(data) ⇒ Object

Public: Create a Response 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 Response.

Examples

Reporter::Record::Response.factory({
  "questionPrompt" => "How many coffees have you had?",
  "numericResponse" => "0",
})
=> #<Reporter::Record::Response::Numeric>


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reporter/record/response.rb', line 27

def self.factory(data)
  klass = if data.has_key? "locationResponse"
            Reporter::Record::Response::Location
          elsif data.has_key? "answeredOptions"
            Reporter::Record::Response::MultipleChoice
          elsif data.has_key? "numericResponse"
            Reporter::Record::Response::Numeric
          elsif data.has_key? "textResponse"
            Reporter::Record::Response::Note
          else
            Reporter::Record::Response::Token
          end

  klass.new data
end