Class: Gamefic::Props::MultipleChoice
- Defined in:
- lib/gamefic/props/multiple_choice.rb
Overview
Props for MultipleChoice scenes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#invalid_message ⇒ String
A message to send the player for an invalid choice.
Attributes inherited from Default
Instance Method Summary collapse
-
#index ⇒ Integer?
The zero-based index of the selected option.
-
#index_of(option) ⇒ Integer?
Get the index of an option using input criteria, e.g., a one-based number or the text of the option.
-
#number ⇒ Integer?
The one-based index of the selected option.
-
#options ⇒ Array<String>
The array of available options.
- #selected? ⇒ Boolean
-
#selection ⇒ String?
The full text of the selected option.
Methods inherited from Default
Instance Attribute Details
#invalid_message ⇒ String
A message to send the player for an invalid choice. A formatting token named ‘%<input>s` can be used to inject the user input.
25 26 27 |
# File 'lib/gamefic/props/multiple_choice.rb', line 25 def @invalid_message ||= '"%<input>s" is not a valid choice.' end |
Instance Method Details
#index ⇒ Integer?
The zero-based index of the selected option.
32 33 34 35 36 |
# File 'lib/gamefic/props/multiple_choice.rb', line 32 def index return nil unless input @index ||= index_of(input) end |
#index_of(option) ⇒ Integer?
Get the index of an option using input criteria, e.g., a one-based number or the text of the option. The return value is the option’s zero-based index or nil.
73 74 75 |
# File 'lib/gamefic/props/multiple_choice.rb', line 73 def index_of(option) index_by_number(option) || index_by_text(option) end |
#number ⇒ Integer?
The one-based index of the selected option.
41 42 43 44 45 |
# File 'lib/gamefic/props/multiple_choice.rb', line 41 def number return nil unless index index + 1 end |
#options ⇒ Array<String>
The array of available options.
14 15 16 |
# File 'lib/gamefic/props/multiple_choice.rb', line 14 def @options ||= [] end |
#selected? ⇒ Boolean
56 57 58 |
# File 'lib/gamefic/props/multiple_choice.rb', line 56 def selected? !!index end |
#selection ⇒ String?
The full text of the selected option.
50 51 52 53 54 |
# File 'lib/gamefic/props/multiple_choice.rb', line 50 def selection return nil unless index [index] end |