Class: DInstaller::Question

Inherits:
Object
  • Object
show all
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

LuksActivationQuestion

Defined Under Namespace

Classes: IdGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = options
  @default_option = default_option
end

Instance Attribute Details

#answerSymbol?

Answer of the question

Returns:

  • (Symbol, nil)

    nil if the question is not answered yet



55
56
57
# File 'lib/dinstaller/question.rb', line 55

def answer
  @answer
end

#default_optionSymbol? (readonly)

Default option to use as answer

Returns:

  • (Symbol, nil)


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

def default_option
  @default_option
end

#idInteger (readonly)

Each question is identified by an unique id

Returns:

  • (Integer)


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

def id
  @id
end

#optionsArray<Symbol> (readonly)

Options the question offers

The question must be answered with one of that options.

Returns:

  • (Array<Symbol>)


45
46
47
# File 'lib/dinstaller/question.rb', line 45

def options
  @options
end

#textString (readonly)

Text of the question

Returns:

  • (String)


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

Returns:

  • (Boolean)


78
79
80
# File 'lib/dinstaller/question.rb', line 78

def answered?
  !answer.nil?
end