Class: Vedeu::Menus::Menu Private
- Inherits:
-
Object
- Object
- Vedeu::Menus::Menu
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/menus/menu.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Converts the collection passed into a list of menu items which can be navigated using the instance methods or events provided.
Instance Attribute Summary collapse
- #collection ⇒ Array private
-
#current ⇒ Fixnum
Returns the index of the value in the collection which is current.
-
#name ⇒ String
The name of the menu.
-
#selected ⇒ Fixnum
Returns the index of the value in the collection which is selected.
Attributes included from Repositories::Model
Instance Method Summary collapse
-
#bottom_item ⇒ Array
private
Sets the value of current to be the last item of the collection.
-
#current_item ⇒ void
private
Returns the item from the collection which shares the same index as the value of #current.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#deputy(client = nil) ⇒ Vedeu::Menus::DSL
private
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#deselect_item ⇒ Array
private
Removes the value of ‘selected`, meaning no items are selected.
-
#initialize(attributes = {}) ⇒ Vedeu::Menus::Menu
constructor
private
Returns a new instance of Vedeu::Menus::Menu.
-
#items ⇒ Array
private
Returns a new collection of items.
-
#last ⇒ Fixnum
private
Returns the last index of the collection.
-
#next_item ⇒ Array
private
Sets the value of current to be the next item in the collection until we reach the last.
-
#prev_item ⇒ Array
private
Sets the value of current to be the previous item in the collection until we reach the first.
-
#select_item ⇒ Array
private
Sets the selected item to be the same value as the current item.
-
#selected_item ⇒ |NilClass
private
Returns the item from the collection which shares the same index as the value of #selected.
-
#size ⇒ Fixnum
private
Returns the size of the collection.
-
#top_item ⇒ Array
private
Sets the value of current to be the first item of the collection.
-
#view ⇒ Array
private
Returns a subset of all the items.
Methods included from Repositories::Model
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Menus::Menu
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Menus::Menu.
49 50 51 52 53 |
# File 'lib/vedeu/menus/menu.rb', line 49 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#collection ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 |
# File 'lib/vedeu/menus/menu.rb', line 56 def collection @collection || [] end |
#current ⇒ Fixnum
Returns the index of the value in the collection which is current.
25 26 27 |
# File 'lib/vedeu/menus/menu.rb', line 25 def current @current end |
#name ⇒ String
The name of the menu. Used to reference the menu throughout the application’s execution lifetime.
32 33 34 |
# File 'lib/vedeu/menus/menu.rb', line 32 def name @name end |
#selected ⇒ Fixnum
Returns the index of the value in the collection which is selected.
39 40 41 |
# File 'lib/vedeu/menus/menu.rb', line 39 def selected @selected end |
Instance Method Details
#bottom_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the value of current to be the last item of the collection.
143 144 145 146 147 |
# File 'lib/vedeu/menus/menu.rb', line 143 def bottom_item @current = last items end |
#current_item ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Returns the item from the collection which shares the same index as the value of #current.
64 65 66 |
# File 'lib/vedeu/menus/menu.rb', line 64 def current_item collection[@current] end |
#defaults ⇒ Hash<Symbol => void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default options/attributes for a new instance of this class.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/vedeu/menus/menu.rb', line 206 def defaults { client: nil, collection: [], current: 0, name: nil, repository: Vedeu., selected: nil, } end |
#deputy(client = nil) ⇒ Vedeu::Menus::DSL
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a DSL instance responsible for defining the DSL methods of this model.
76 77 78 |
# File 'lib/vedeu/menus/menu.rb', line 76 def deputy(client = nil) Vedeu::Menus::DSL.new(self, client) end |
#deselect_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Removes the value of ‘selected`, meaning no items are selected.
183 184 185 186 187 |
# File 'lib/vedeu/menus/menu.rb', line 183 def deselect_item @selected = nil items end |
#items ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new collection of items. Each element of the collection is of the format:
[selected, current, item]
‘selected` is a boolean indicating whether the item is selected. `current` is a boolean indicating whether the item is current. `item` is the item itself.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vedeu/menus/menu.rb', line 102 def items items = [] collection.each_with_index do |item, index| items << if index == @current && index == @selected [true, true, item] elsif index == @current [false, true, item] elsif index == @selected [true, false, item] else [false, false, item] end end items end |
#last ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the last index of the collection.
192 193 194 |
# File 'lib/vedeu/menus/menu.rb', line 192 def last collection.size - 1 end |
#next_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the value of current to be the next item in the collection until we reach the last.
153 154 155 156 157 |
# File 'lib/vedeu/menus/menu.rb', line 153 def next_item @current += 1 if @current < last items end |
#prev_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the value of current to be the previous item in the collection until we reach the first.
163 164 165 166 167 |
# File 'lib/vedeu/menus/menu.rb', line 163 def prev_item @current -= 1 if @current > 0 items end |
#select_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the selected item to be the same value as the current item.
173 174 175 176 177 |
# File 'lib/vedeu/menus/menu.rb', line 173 def select_item @selected = @current items end |
#selected_item ⇒ |NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the item from the collection which shares the same index as the value of #selected.
84 85 86 87 88 |
# File 'lib/vedeu/menus/menu.rb', line 84 def selected_item return nil unless @selected collection[@selected] end |
#size ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the size of the collection.
199 200 201 |
# File 'lib/vedeu/menus/menu.rb', line 199 def size collection.size end |
#top_item ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the value of current to be the first item of the collection.
133 134 135 136 137 |
# File 'lib/vedeu/menus/menu.rb', line 133 def top_item @current = 0 items end |
#view ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a subset of all the items.
125 126 127 |
# File 'lib/vedeu/menus/menu.rb', line 125 def view items[@current, collection.size] end |