Class: TypedForm::FormData::Answers

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/typed_form/form_data/answers.rb

Overview

A collection class which takes a collection of answers to a form, and associates the questions with answers.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#input_questionsObject (readonly)

Returns the value of attribute input_questions.



27
28
29
# File 'lib/typed_form/form_data/answers.rb', line 27

def input_questions
  @input_questions
end

#parsed_questionsArendelle (readonly)

An immutable object representing the question data from the form.

Returns:

  • (Arendelle)

    the current value of parsed_questions



12
13
14
# File 'lib/typed_form/form_data/answers.rb', line 12

def parsed_questions
  @parsed_questions
end

#parsed_responseArendelle (readonly)

An immutable object representing the submission data from the form.

Returns:

  • (Arendelle)

    the current value of parsed_response



12
13
14
# File 'lib/typed_form/form_data/answers.rb', line 12

def parsed_response
  @parsed_response
end

Class Method Details

.collate(parsed_response:, parsed_questions:, input_questions:) ⇒ Array<Question>

Builds a collection of Questions, with text extrapolated to support "piped" questions (i.e. "What is the name of your {answer_42}").

Returns:

  • (Array<Question>)

    Question value objects with extrapolated text and answers.



34
35
36
37
38
# File 'lib/typed_form/form_data/answers.rb', line 34

def self.collate(parsed_response:, parsed_questions:, input_questions:)
  new(parsed_response: parsed_response,
      parsed_questions: parsed_questions,
      input_questions: input_questions).questions
end

Instance Method Details

#answersArendelle

Returns Parsed Questions from Typeform Data API JSON.

Returns:

  • (Arendelle)

    Parsed Questions from Typeform Data API JSON



21
# File 'lib/typed_form/form_data/answers.rb', line 21

def_delegators :parsed_response, :answers, :metadata, :token

#metadataArendelle

Returns Parsed Metadata from Typeform Data API JSON.

Returns:

  • (Arendelle)

    Parsed Metadata from Typeform Data API JSON



21
# File 'lib/typed_form/form_data/answers.rb', line 21

def_delegators :parsed_response, :answers, :metadata, :token

#questionsArray<Question>

Iterates through the existing collection of input questions to build a set of question value objects. Memoizes result.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/typed_form/form_data/answers.rb', line 43

def questions
  @_questions ||= input_questions.map do |question|
    text_answers = answers_for(question.ids)

    Question.with_response_data(
      question: question,
      answer: typecast_answer(answer: text_answers, type: question.type),
      text: extrapolated_question_text(question),
      original_answer: text_answers
    )
  end
end

#tokenString

Returns date form was submitted, in UTC.

Returns:

  • (String)

    date form was submitted, in UTC



21
# File 'lib/typed_form/form_data/answers.rb', line 21

def_delegators :parsed_response, :answers, :metadata, :token