Class: Gipper::Answer

Inherits:
Object
  • Object
show all
Includes:
SpecialCharacterHandler, Oniguruma
Defined in:
lib/answer.rb

Overview

Gipper::Answer

Represents the single correct answer if there is only one answer, or one of the answer choices if multiple are provided for a question.

To populate the answer from a string use the parse method

answer = Gipper::Answer.new
answer.parse "= foo #bar"

answer.correct
>> true

answer.text
>> foo

answer.comment
>> bar

or

answer.parse "F"

answer.correct
>> false

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



33
34
35
# File 'lib/answer.rb', line 33

def comment
  @comment
end

#correctObject (readonly)

Returns the value of attribute correct.



33
34
35
# File 'lib/answer.rb', line 33

def correct
  @correct
end

#rangeObject (readonly)

Returns the value of attribute range.



33
34
35
# File 'lib/answer.rb', line 33

def range
  @range
end

#textObject (readonly)

Returns the value of attribute text.



33
34
35
# File 'lib/answer.rb', line 33

def text
  @text
end

#weightObject (readonly)

Returns the value of attribute weight.



33
34
35
# File 'lib/answer.rb', line 33

def weight
  @weight
end

Instance Method Details

#parse(answer, style_hint = nil) ⇒ Object

Will parse a single answer into it’s parts. If the answer type is numerical, pass :numerical as the optional second parameter.



37
38
39
40
41
42
43
# File 'lib/answer.rb', line 37

def parse answer, style_hint = nil
  if style_hint == :numerical
    parse_as_numerical answer
  else
    parse_standard answer
  end
end