Class: QuestionproRails::Question

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Question

Returns a new instance of Question.



11
12
13
14
15
16
# File 'lib/questionpro_rails/question.rb', line 11

def initialize (attributes)
  @id           = attributes['id']
  @order_number = attributes['orderNumber']          
  @text         = attributes['text']
  @qp_answers   = attributes['answers']
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/questionpro_rails/question.rb', line 6

def id
  @id
end

#order_numberObject (readonly)

Returns the value of attribute order_number.



6
7
8
# File 'lib/questionpro_rails/question.rb', line 6

def order_number
  @order_number
end

#qp_answersArray<Hash> (readonly)

Returns Choices available for the question.

Returns:

  • (Array<Hash>)

    Choices available for the question.



9
10
11
# File 'lib/questionpro_rails/question.rb', line 9

def qp_answers
  @qp_answers
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/questionpro_rails/question.rb', line 6

def text
  @text
end

Instance Method Details

#choicesArray<QuestionproRails::Choice>

Extract the choices from the hashes stored inside qp_answers attribute.

Returns:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/questionpro_rails/question.rb', line 22

def choices
  extracted_choices = []

  unless self.qp_answers.nil?
    self.qp_answers.each do |choice|   
      extracted_choices.push(Choice.new(choice))
    end           
  end

  return extracted_choices        
end