Class: Answer

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ruql/answer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(answer_text = '', correct = false, explanation = nil) ⇒ Answer

Returns a new instance of Answer.



11
12
13
14
15
# File 'lib/ruql/answer.rb', line 11

def initialize(answer_text = '', correct = false, explanation=nil)
  @answer_text = answer_text
  @correct = !!correct # ensure boolean
  @explanation = explanation
end

Instance Attribute Details

#answer_textObject

Returns the value of attribute answer_text.



3
4
5
# File 'lib/ruql/answer.rb', line 3

def answer_text
  @answer_text
end

#builderObject (readonly)

Returns the value of attribute builder.



5
6
7
# File 'lib/ruql/answer.rb', line 5

def builder
  @builder
end

#correctObject

Returns the value of attribute correct.



3
4
5
# File 'lib/ruql/answer.rb', line 3

def correct
  @correct
end

#explanationObject

Returns the value of attribute explanation.



3
4
5
# File 'lib/ruql/answer.rb', line 3

def explanation
  @explanation
end

#questionObject (readonly)

Returns the value of attribute question.



6
7
8
# File 'lib/ruql/answer.rb', line 6

def question
  @question
end

Class Method Details

.from_JSON(hash) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ruql/answer.rb', line 21

def self.from_JSON(hash)
  answer = Answer.new
  hash.each do |key, value|
    answer.send((key + '=').to_sym, value)
  end
  answer
end

Instance Method Details

#<=>(other) ⇒ Object



8
# File 'lib/ruql/answer.rb', line 8

def <=>(other) ; self.answer_text <=> other.answer_text ; end

#correct?Boolean

Returns:

  • (Boolean)


9
# File 'lib/ruql/answer.rb', line 9

def correct? ; !!correct ; end

#has_explanation?Boolean

Returns:

  • (Boolean)


10
# File 'lib/ruql/answer.rb', line 10

def has_explanation? ; !!explanation ; end

#to_JSONObject



17
18
19
# File 'lib/ruql/answer.rb', line 17

def to_JSON
  Hash[instance_variables.collect { |var| [var.to_s.delete('@'), instance_variable_get(var)] }]
end