Class: Answer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(answer_text, correct, 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, 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 (readonly)

Returns the value of attribute correct.



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

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

Instance Method Details

#<=>(other) ⇒ Object



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

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

#as_jsonObject



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

def as_json
  Hash(:text => @answer_text, :correct => @correct,:explanation => @explanation).compact
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