Class: Vedeu::Menus::Menu Private

Inherits:
Object
  • Object
show all
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

Attributes included from Repositories::Model

#repository

Instance Method Summary collapse

Methods included from Repositories::Model

included, #store

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.

Parameters:

  • attributes (Hash) (defaults to: {})

Options Hash (attributes):

  • collection (Array)
  • name (String|Symbol)
  • current (Fixnum)
  • selected (Fixnum|NilClass)


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

#collectionArray

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:

  • (Array)


56
57
58
# File 'lib/vedeu/menus/menu.rb', line 56

def collection
  @collection || []
end

#currentFixnum

Returns the index of the value in the collection which is current.

Returns:

  • (Fixnum)


25
26
27
# File 'lib/vedeu/menus/menu.rb', line 25

def current
  @current
end

#nameString

The name of the menu. Used to reference the menu throughout the application’s execution lifetime.

Returns:

  • (String)


32
33
34
# File 'lib/vedeu/menus/menu.rb', line 32

def name
  @name
end

#selectedFixnum

Returns the index of the value in the collection which is selected.

Returns:

  • (Fixnum)


39
40
41
# File 'lib/vedeu/menus/menu.rb', line 39

def selected
  @selected
end

Instance Method Details

#bottom_itemArray

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.

Returns:

  • (Array)


143
144
145
146
147
# File 'lib/vedeu/menus/menu.rb', line 143

def bottom_item
  @current = last

  items
end

#current_itemvoid

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

#defaultsHash<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.

Returns:

  • (Hash<Symbol => void>)


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.menus,
    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.

Parameters:

  • client (Object|NilClass) (defaults to: nil)

    The client binding represents the client application object that is currently invoking a DSL method. It is required so that we can send messages to the client application object should we need to.

Returns:



76
77
78
# File 'lib/vedeu/menus/menu.rb', line 76

def deputy(client = nil)
  Vedeu::Menus::DSL.new(self, client)
end

#deselect_itemArray

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.

Returns:

  • (Array)


183
184
185
186
187
# File 'lib/vedeu/menus/menu.rb', line 183

def deselect_item
  @selected = nil

  items
end

#itemsArray

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.

Returns:

  • (Array)


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

#lastFixnum

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.

Returns:

  • (Fixnum)


192
193
194
# File 'lib/vedeu/menus/menu.rb', line 192

def last
  collection.size - 1
end

#next_itemArray

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.

Returns:

  • (Array)


153
154
155
156
157
# File 'lib/vedeu/menus/menu.rb', line 153

def next_item
  @current += 1 if @current < last

  items
end

#prev_itemArray

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.

Returns:

  • (Array)


163
164
165
166
167
# File 'lib/vedeu/menus/menu.rb', line 163

def prev_item
  @current -= 1 if @current > 0

  items
end

#select_itemArray

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.

Returns:

  • (Array)


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.

Returns:

  • (|NilClass)


84
85
86
87
88
# File 'lib/vedeu/menus/menu.rb', line 84

def selected_item
  return nil unless @selected

  collection[@selected]
end

#sizeFixnum

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.

Returns:

  • (Fixnum)


199
200
201
# File 'lib/vedeu/menus/menu.rb', line 199

def size
  collection.size
end

#top_itemArray

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.

Returns:

  • (Array)


133
134
135
136
137
# File 'lib/vedeu/menus/menu.rb', line 133

def top_item
  @current = 0

  items
end

#viewArray

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.

Returns:

  • (Array)


125
126
127
# File 'lib/vedeu/menus/menu.rb', line 125

def view
  items[@current, collection.size]
end