Class: Surveymonkey::Response::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/surveymonkey_api/response/question.rb

Overview

Response Question

Defined Under Namespace

Classes: Answer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data, question_structure) ⇒ Question

Returns a new instance of Question.



6
7
8
9
10
# File 'lib/surveymonkey_api/response/question.rb', line 6

def initialize(raw_data, question_structure)
  @raw_data = raw_data
  @id = raw_data['id']
  @question_structure = question_structure
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/surveymonkey_api/response/question.rb', line 4

def id
  @id
end

#question_structureObject (readonly)

Returns the value of attribute question_structure.



4
5
6
# File 'lib/surveymonkey_api/response/question.rb', line 4

def question_structure
  @question_structure
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



4
5
6
# File 'lib/surveymonkey_api/response/question.rb', line 4

def raw_data
  @raw_data
end

Instance Method Details

#answersObject



17
18
19
20
21
22
# File 'lib/surveymonkey_api/response/question.rb', line 17

def answers
  @answers ||= raw_data['answers'].each_with_object([]) do |answer, arr|
    answer_structure = question_structure['answers']
    arr << Surveymonkey::Response::Question::Answer.new(answer, answer_structure)
  end
end

#titleObject

Match response title



13
14
15
# File 'lib/surveymonkey_api/response/question.rb', line 13

def title
  @title ||= question_structure['headings'].first['heading']
end