Class: Gamefic::Props::MultipleChoice

Inherits:
Default
  • Object
show all
Defined in:
lib/gamefic/props/multiple_choice.rb

Overview

Props for MultipleChoice scenes.

Direct Known Subclasses

YesOrNo

Instance Attribute Summary collapse

Attributes inherited from Default

#context, #input, #prompt, #scene

Instance Method Summary collapse

Methods inherited from Default

#initialize, #output

Constructor Details

This class inherits a constructor from Gamefic::Props::Default

Instance Attribute Details

#invalid_messageObject



21
22
23
# File 'lib/gamefic/props/multiple_choice.rb', line 21

def invalid_message
  @invalid_message ||= '"%<input>s" is not a valid choice.'
end

Instance Method Details

#indexInteger?

The zero-based index of the selected option.

Returns:

  • (Integer, nil)


28
29
30
31
32
# File 'lib/gamefic/props/multiple_choice.rb', line 28

def index
  return nil unless input

  @index ||= index_by_number || index_by_text
end

#numberInteger?

The one-based index of the selected option.

Returns:

  • (Integer, nil)


37
38
39
40
41
# File 'lib/gamefic/props/multiple_choice.rb', line 37

def number
  return nil unless index

  index + 1
end

#optionsArray<String>

The array of available options.

Returns:



17
18
19
# File 'lib/gamefic/props/multiple_choice.rb', line 17

def options
  @options ||= []
end

#selectionString?

The full text of the selected option.

Returns:



46
47
48
49
50
# File 'lib/gamefic/props/multiple_choice.rb', line 46

def selection
  return nil unless index

  options[index]
end