Class: DInstaller::Question
- Inherits:
-
Object
- Object
- DInstaller::Question
- Defined in:
- lib/dinstaller/question.rb
Overview
This class represents a question
Questions are used when some information needs to be asked. For example, a question could be created for asking whether to continue or not when an error is detected.
Questions are managed by a questions manager, see QuestionsManager.
Direct Known Subclasses
Defined Under Namespace
Classes: IdGenerator
Instance Attribute Summary collapse
-
#answer ⇒ Symbol?
Answer of the question.
-
#default_option ⇒ Symbol?
readonly
Default option to use as answer.
-
#id ⇒ Integer
readonly
Each question is identified by an unique id.
-
#options ⇒ Array<Symbol>
readonly
Options the question offers.
-
#text ⇒ String
readonly
Text of the question.
Instance Method Summary collapse
-
#answered? ⇒ Boolean
Whether the question is already answered.
-
#initialize(text, options: [], default_option: nil) ⇒ Question
constructor
A new instance of Question.
Constructor Details
#initialize(text, options: [], default_option: nil) ⇒ Question
Returns a new instance of Question.
57 58 59 60 61 62 |
# File 'lib/dinstaller/question.rb', line 57 def initialize(text, options: [], default_option: nil) @id = IdGenerator.next @text = text @options = @default_option = default_option end |
Instance Attribute Details
#answer ⇒ Symbol?
Answer of the question
55 56 57 |
# File 'lib/dinstaller/question.rb', line 55 def answer @answer end |
#default_option ⇒ Symbol? (readonly)
Default option to use as answer
50 51 52 |
# File 'lib/dinstaller/question.rb', line 50 def default_option @default_option end |
#id ⇒ Integer (readonly)
Each question is identified by an unique id
33 34 35 |
# File 'lib/dinstaller/question.rb', line 33 def id @id end |
#options ⇒ Array<Symbol> (readonly)
Options the question offers
The question must be answered with one of that options.
45 46 47 |
# File 'lib/dinstaller/question.rb', line 45 def @options end |
#text ⇒ String (readonly)
Text of the question
38 39 40 |
# File 'lib/dinstaller/question.rb', line 38 def text @text end |
Instance Method Details
#answered? ⇒ Boolean
Whether the question is already answered
78 79 80 |
# File 'lib/dinstaller/question.rb', line 78 def answered? !answer.nil? end |