Class: ULL::ETSII::Alu3177::Quiz::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/ULL-ETSII-Alu3177-Quiz/quiz.rb

Overview

Clase que representa una de pregunta a un test.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, anss) ⇒ Question

Recibe un título title de la pregunta y el resto de parámetros son las posibles respuestas.

Raises:

  • (ArgumentError)


132
133
134
135
136
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 132

def initialize(title, anss)
    raise ArgumentError, "Title has to be a String, got #{title.class}" unless title.is_a? String
    @title = title
    @answers = anss
end

Instance Attribute Details

#answersObject

Returns the value of attribute answers.



129
130
131
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 129

def answers
  @answers
end

#titleObject

Returns the value of attribute title.



129
130
131
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 129

def title
  @title
end

Instance Method Details

#to_sObject

Representación visual de una pregunta en forma de String.



139
140
141
142
143
144
145
146
147
# File 'lib/ULL-ETSII-Alu3177-Quiz/quiz.rb', line 139

def to_s
    out = "# #{@title}".colorize(:light_blue) + "\n"
    i = 1
    answers.each do |a|
        out << "  [#{i}] #{a}\n"
        i += 1
    end
    out
end