Class: Vedeu::Menus::Menu
- Inherits:
-
Object
- Object
- Vedeu::Menus::Menu
- Includes:
- Repositories::Model
- Defined in:
- lib/vedeu/menus/menu.rb
Overview
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
-
#current ⇒ Fixnum
Returns the index of the value in the collection which is current.
-
#name ⇒ String
The name of the menu.
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
-
#selected ⇒ Fixnum
Returns the index of the value in the collection which is selected.
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#bottom_item ⇒ Array
Sets the value of current to be the last item of the collection.
-
#current_item ⇒ void
Returns the item from the collection which shares the same index as the value of #current.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#deputy(client = nil) ⇒ Vedeu::Menus::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#deselect_item ⇒ Array
Removes the value of ‘selected`, meaning no items are selected.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(attributes = {}) ⇒ Vedeu::Menus::Menu
constructor
Returns a new instance of Vedeu::Menus::Menu.
-
#items ⇒ Array
Returns a new collection of items.
-
#last ⇒ Fixnum
Returns the last index of the collection.
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#next_item ⇒ Array
Sets the value of current to be the next item in the collection until we reach the last.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#prev_item ⇒ Array
Sets the value of current to be the previous item in the collection until we reach the first.
-
#select_item ⇒ Array
Sets the selected item to be the same value as the current item.
-
#selected_item ⇒ |NilClass
Returns the item from the collection which shares the same index as the value of #selected.
-
#size ⇒ Fixnum
Returns the size of the collection.
-
#snake_case(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store(&block) ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#top_item ⇒ Array
Sets the value of current to be the first item of the collection.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view ⇒ Array
Returns a subset of all the items.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Menus::Menu
Returns a new instance of Vedeu::Menus::Menu.
47 48 49 50 51 |
# File 'lib/vedeu/menus/menu.rb', line 47 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#collection ⇒ Array
16 17 18 |
# File 'lib/vedeu/menus/menu.rb', line 16 def collection @collection end |
#current ⇒ Fixnum
Returns the index of the value in the collection which is current.
23 24 25 |
# File 'lib/vedeu/menus/menu.rb', line 23 def current @current end |
#name ⇒ String
The name of the menu. Used to reference the menu throughout the application’s execution lifetime.
30 31 32 |
# File 'lib/vedeu/menus/menu.rb', line 30 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
#selected ⇒ Fixnum
Returns the index of the value in the collection which is selected.
37 38 39 |
# File 'lib/vedeu/menus/menu.rb', line 37 def selected @selected end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable is nil or empty.
#become(klass, attributes) ⇒ Class Originally defined in module Common
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.
Converts one class into another.
#boolean(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating the value was a boolean.
#boolean?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Boolean.
#bottom_item ⇒ Array
Sets the value of current to be the last item of the collection.
136 137 138 139 140 |
# File 'lib/vedeu/menus/menu.rb', line 136 def bottom_item @current = last items end |
#current_item ⇒ void
This method returns an undefined value.
Returns the item from the collection which shares the same index as the value of #current.
57 58 59 |
# File 'lib/vedeu/menus/menu.rb', line 57 def current_item @collection[@current] end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/vedeu/menus/menu.rb', line 201 def defaults { client: nil, collection: [], current: 0, name: '', repository: Vedeu., selected: nil, } end |
#deputy(client = nil) ⇒ Vedeu::Menus::DSL
Returns a DSL instance responsible for defining the DSL methods of this model.
69 70 71 |
# File 'lib/vedeu/menus/menu.rb', line 69 def deputy(client = nil) Vedeu::Menus::DSL.new(self, client) end |
#deselect_item ⇒ Array
Removes the value of ‘selected`, meaning no items are selected.
176 177 178 179 180 |
# File 'lib/vedeu/menus/menu.rb', line 176 def deselect_item @selected = nil items end |
#escape?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value should be considered false.
#hash?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Hash.
#items ⇒ Array
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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vedeu/menus/menu.rb', line 95 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
Returns the last index of the collection.
185 186 187 |
# File 'lib/vedeu/menus/menu.rb', line 185 def last @collection.size - 1 end |
#line_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::Line.
#next_item ⇒ Array
Sets the value of current to be the next item in the collection until we reach the last.
146 147 148 149 150 |
# File 'lib/vedeu/menus/menu.rb', line 146 def next_item @current += 1 if @current < last items end |
#numeric?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Fixnum.
#present?(variable) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether a variable has a useful value.
#prev_item ⇒ Array
Sets the value of current to be the previous item in the collection until we reach the first.
156 157 158 159 160 |
# File 'lib/vedeu/menus/menu.rb', line 156 def prev_item @current -= 1 if @current > 0 items end |
#select_item ⇒ Array
Sets the selected item to be the same value as the current item.
166 167 168 169 170 |
# File 'lib/vedeu/menus/menu.rb', line 166 def select_item @selected = @current items end |
#selected_item ⇒ |NilClass
Returns the item from the collection which shares the same index as the value of #selected.
77 78 79 80 81 |
# File 'lib/vedeu/menus/menu.rb', line 77 def selected_item return nil unless @selected @collection[@selected] end |
#size ⇒ Fixnum
Returns the size of the collection.
192 193 194 |
# File 'lib/vedeu/menus/menu.rb', line 192 def size @collection.size end |
#snake_case(klass) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
#store(&block) ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#stream_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::Stream.
#string?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value is a Fixnum.
#top_item ⇒ Array
Sets the value of current to be the first item of the collection.
126 127 128 129 130 |
# File 'lib/vedeu/menus/menu.rb', line 126 def top_item @current = 0 items end |
#truthy?(value) ⇒ Boolean Originally defined in module Common
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 boolean indicating whether the value should be considered true.
#view ⇒ Array
Returns a subset of all the items.
118 119 120 |
# File 'lib/vedeu/menus/menu.rb', line 118 def view items[@current, @collection.size] end |
#view_model? ⇒ Boolean Originally defined in module Common
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 boolean indicating the model is a Views::View.