Class: TypedForm::FormData::Question
- Inherits:
-
Object
- Object
- TypedForm::FormData::Question
- Defined in:
- lib/typed_form/form_data/question.rb
Overview
Question value objects represent the Typeform concept of a question, but expose an interface for querying questions and answers.
Instance Attribute Summary collapse
-
#answer ⇒ String
The answer of the question.
-
#field_id ⇒ Integer
readonly
The Typeform Field ID for the question.
-
#ids ⇒ Array<Strong>
readonly
The Typeform IDs for the question.
-
#original_answer ⇒ Object
Returns the value of attribute original_answer.
-
#original_text ⇒ Object
readonly
Returns the value of attribute original_text.
-
#text ⇒ Object
Returns the value of attribute text.
-
#The ⇒ String
readonly
original text for the question before answers are extrapolated back into the question.
Class Method Summary collapse
-
.with_response_data(question:, text:, answer:, original_answer:) ⇒ Question
Creates a new Question with existing data from a previous question.
Instance Method Summary collapse
-
#initialize(ids:, field_id:, original_text:) ⇒ Question
constructor
Creates a new Question value object, which represents any number of questions in a Typeform Form that can be logically represented as a single question.
-
#type ⇒ Object
Splits into an array based on the id of the question, to determine the Type of object.
Constructor Details
#initialize(ids:, field_id:, original_text:) ⇒ Question
Creates a new Question value object, which represents any number of questions in a Typeform Form that can be logically represented as a single question. This includes both single question fields and fields like multiple choice, picture choice, etc.
29 30 31 32 33 |
# File 'lib/typed_form/form_data/question.rb', line 29 def initialize(ids:, field_id:, original_text:) @ids = ids @field_id = field_id @original_text = original_text end |
Instance Attribute Details
#answer ⇒ String
The answer of the question.
14 15 16 |
# File 'lib/typed_form/form_data/question.rb', line 14 def answer @answer end |
#field_id ⇒ Integer (readonly)
The Typeform Field ID for the question
14 15 16 |
# File 'lib/typed_form/form_data/question.rb', line 14 def field_id @field_id end |
#ids ⇒ Array<Strong> (readonly)
The Typeform IDs for the question. This is ids instead of id because of the way Typeform represents multiple choice questions.
14 15 16 |
# File 'lib/typed_form/form_data/question.rb', line 14 def ids @ids end |
#original_answer ⇒ Object
Returns the value of attribute original_answer.
16 17 18 |
# File 'lib/typed_form/form_data/question.rb', line 16 def original_answer @original_answer end |
#original_text ⇒ Object (readonly)
Returns the value of attribute original_text.
15 16 17 |
# File 'lib/typed_form/form_data/question.rb', line 15 def original_text @original_text end |
#text ⇒ Object
Returns the value of attribute text.
16 17 18 |
# File 'lib/typed_form/form_data/question.rb', line 16 def text @text end |
#The ⇒ String (readonly)
original text for the question before answers are extrapolated back into the question.
14 15 16 |
# File 'lib/typed_form/form_data/question.rb', line 14 def The @The end |
Class Method Details
.with_response_data(question:, text:, answer:, original_answer:) ⇒ Question
Creates a new Question with existing data from a previous question.
48 49 50 51 52 53 54 |
# File 'lib/typed_form/form_data/question.rb', line 48 def self.with_response_data(question:, text:, answer:, original_answer:) question.dup.tap do |new_question| new_question.answer = answer new_question.original_answer = original_answer new_question.text = text end.freeze end |
Instance Method Details
#type ⇒ Object
Splits into an array based on the id of the question, to determine the Type of object. This information can be queried in order to allow users to handle various types of Typeform data differently.
38 39 40 41 42 |
# File 'lib/typed_form/form_data/question.rb', line 38 def type detected_type = ids.map { |id| id.split("_")[0] }.uniq return detected_type.first if detected_type.size == 1 raise StandardError, "Cannot detect type of question ids #{ids}" end |