Class: Poptart::Question
- Extended by:
- Request
- Defined in:
- lib/poptart/question.rb
Direct Known Subclasses
BooleanQuestion, MultipleResponseQuestion, RangeQuestion, TimeQuestion
Instance Attribute Summary collapse
-
#absolute_index ⇒ Object
Returns the value of attribute absolute_index.
-
#freeform ⇒ Object
Returns the value of attribute freeform.
-
#key ⇒ Object
Returns the value of attribute key.
-
#parent_question_id ⇒ Object
Returns the value of attribute parent_question_id.
-
#question_type ⇒ Object
Returns the value of attribute question_type.
-
#responses ⇒ Object
Returns the value of attribute responses.
Attributes inherited from Model
Class Method Summary collapse
- .all(params = {}) ⇒ Object
- .create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil) ⇒ Object
Instance Method Summary collapse
- #freeform? ⇒ Boolean
-
#initialize(response) ⇒ Question
constructor
A new instance of Question.
Methods included from Request
connection, get, post, put
Methods inherited from Model
#questions_url, root, #survey_questions_url, #surveys_url, #users_url
Constructor Details
#initialize(response) ⇒ Question
Returns a new instance of Question.
7 8 9 10 11 12 13 14 15 |
# File 'lib/poptart/question.rb', line 7 def initialize(response) super @responses = params['responses'] @freeform = params['freeform'] @question_type = params['question_type'] @absolute_index = params['absolute_index'] @parent_question_id = params['parent_question_id'] @key = params['key'] end |
Instance Attribute Details
#absolute_index ⇒ Object
Returns the value of attribute absolute_index.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def absolute_index @absolute_index end |
#freeform ⇒ Object
Returns the value of attribute freeform.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def freeform @freeform end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def key @key end |
#parent_question_id ⇒ Object
Returns the value of attribute parent_question_id.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def parent_question_id @parent_question_id end |
#question_type ⇒ Object
Returns the value of attribute question_type.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def question_type @question_type end |
#responses ⇒ Object
Returns the value of attribute responses.
5 6 7 |
# File 'lib/poptart/question.rb', line 5 def responses @responses end |
Class Method Details
.all(params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/poptart/question.rb', line 28 def self.all(params = {}) response = get(root.questions_url) JSON.parse(response.body).map do |question| if params[:type] if question['question_type'] == params[:type] new(question) end else new(question) end end.compact end |
.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/poptart/question.rb', line 17 def self.create(text, responses: [], freeform: false, absolute_index: nil, parent_question_id: nil, key: nil) response = post(root.questions_url, question: { question_type: question_type, responses: responses, text: text, freeform: freeform, absolute_index: absolute_index, parent_question_id: parent_question_id, key: key}) new(response) end |
Instance Method Details
#freeform? ⇒ Boolean
41 42 43 |
# File 'lib/poptart/question.rb', line 41 def freeform? @freeform end |