Class: Metro::Model::OptionsProperty::Options
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Metro::Model::OptionsProperty::Options
- Defined in:
- lib/metro/models/properties/options_property/options.rb
Overview
Options maintains the list of menu options that would be displayed in a menu. Each option is a component that can be rendered during the draw phase.
Also, options maintains the currently selected item and has the ability to manage the changes from the previous.
Class Method Summary collapse
-
.empty ⇒ Object
Generate an empty set of options.
Instance Method Summary collapse
-
#current_selected_index ⇒ Fixnum
The index of the current selected option.
-
#current_selected_index=(value) ⇒ Object
Set the index of the currently selected item.
-
#initialize(options) ⇒ Options
constructor
Create options with the provided array of options.
-
#next! ⇒ Object
Move the current selected item to the next item.
-
#previous! ⇒ Object
Move the current selected item to the previous item.
-
#selected ⇒ Object
The currently selected option.
-
#selected_action ⇒ Symbol
The action name of the currently selected option.
-
#unselected ⇒ Array
A list of all the options that are currently not selected.
Constructor Details
#initialize(options) ⇒ Options
Create options with the provided array of options.
27 28 29 |
# File 'lib/metro/models/properties/options_property/options.rb', line 27 def initialize() super() end |
Class Method Details
.empty ⇒ Object
Generate an empty set of options.
17 18 19 |
# File 'lib/metro/models/properties/options_property/options.rb', line 17 def self.empty new [] end |
Instance Method Details
#current_selected_index ⇒ Fixnum
Returns the index of the current selected option.
34 35 36 |
# File 'lib/metro/models/properties/options_property/options.rb', line 34 def current_selected_index @current_selected_index ||= 0 end |
#current_selected_index=(value) ⇒ Object
Set the index of the currently selected item. Values that exceed the possible count of options will reset to the beginning of the list of options. Values that proceed the start of of the list of options will fallback to the last option.
43 44 45 46 47 48 |
# File 'lib/metro/models/properties/options_property/options.rb', line 43 def current_selected_index=(value) @current_selected_index = value || 0 @current_selected_index = 0 if @current_selected_index >= count @current_selected_index = count - 1 if @current_selected_index <= -1 @current_selected_index end |
#next! ⇒ Object
Move the current selected item to the next item
80 81 82 |
# File 'lib/metro/models/properties/options_property/options.rb', line 80 def next! self.current_selected_index += 1 end |
#previous! ⇒ Object
Move the current selected item to the previous item
87 88 89 |
# File 'lib/metro/models/properties/options_property/options.rb', line 87 def previous! self.current_selected_index -= 1 end |
#selected ⇒ Object
Returns the currently selected option.
60 61 62 |
# File 'lib/metro/models/properties/options_property/options.rb', line 60 def selected at(current_selected_index) || NoOption.new end |
#selected_action ⇒ Symbol
The action name of the currently selected option. If no option is currently selected then the NoOption ‘missing_menu_action’ will be returned.
69 70 71 72 73 74 75 |
# File 'lib/metro/models/properties/options_property/options.rb', line 69 def selected_action if selected.respond_to?(:properties) && selected.properties[:action] selected.properties[:action] else selected.to_sym end end |
#unselected ⇒ Array
Returns a list of all the options that are currently not selected.
53 54 55 |
# File 'lib/metro/models/properties/options_property/options.rb', line 53 def unselected self - [ selected ] end |