Module: Robut::Plugin::Quiz::Question

Included in:
Choice, Polar, Range
Defined in:
lib/question.rb

Constant Summary collapse

GROUP_REGEX =

This regex will find all the questions and parameters specified with the question

/['"]([^'"]+)['"]/

Instance Method Summary collapse

Instance Method Details

#askString

Ask the question that has been proposed.

Returns:

  • (String)

    a string that asks the question in the chat room.



49
50
51
# File 'lib/question.rb', line 49

def ask
  "@all Question '#{@question}'"
end

#captured_resultsHash

Maintains a list of the results that have been captured for the question. The hash that is maintained would be used with the user’s nickname as the key and the value as a response to the question.

Returns:

  • (Hash)

    used for storing responses from the various senders.



60
61
62
# File 'lib/question.rb', line 60

def captured_results
  @captured_results ||= {}
end

#initialize(sender, question_with_parameters) ⇒ Object

Initialize the question with the asker of the question and the details about question that is being asked.

Parameters:

  • sender (String)

    the name of the person asking the question.

  • question_with_parameters (String)

    this is the remaining question and parameters left on the question posed to the chat room.



16
17
18
19
# File 'lib/question.rb', line 16

def initialize(sender,question_with_parameters)
  @sender = sender
  process_question(question_with_parameters)
end

#process_question(question_with_parameters) ⇒ Object

This is used internally to process the the question and parameters that sent to the question.

Parameters:

  • question_with_parameters (String)

    this is the remaining question and parameters left on the question posed to the chat room.



28
29
30
31
32
33
34
35
36
37
# File 'lib/question.rb', line 28

def process_question(question_with_parameters)
  
  parsed_elements = question_with_parameters.scan(GROUP_REGEX)
  
  @question = parsed_elements.first.first
  # After the target, question type, question, and answer length has been determined
  # look at all the single quoted items to find the list of parameters if there are any
  @parameters = Array(parsed_elements[1..-1].flatten)
  
end

#to_sString

Returns the question that is being asked.

Returns:

  • (String)

    the question that is being asked.



41
42
43
# File 'lib/question.rb', line 41

def to_s
  @question
end