Class: DynamicMenu::MenuItem
- Inherits:
-
Object
- Object
- DynamicMenu::MenuItem
- Defined in:
- lib/dynamic_menu.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) items
readonly
Returns the value of attribute items.
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) target
readonly
Returns the value of attribute target.
Instance Method Summary (collapse)
- - (Object) [](attribute)
- - (Object) []=(attribute, value)
- - (Boolean) active?
- - (Object) active_item
- - (Object) add(*args, &block)
- - (Object) next
- - (Object) position
- - (Object) previous (also: #prev)
- - (Object) self_or_inherited_attribute(attribute)
Instance Attribute Details
- (Object) items (readonly)
Returns the value of attribute items
5 6 7 |
# File 'lib/dynamic_menu.rb', line 5 def items @items end |
- (Object) name (readonly)
Returns the value of attribute name
4 5 6 |
# File 'lib/dynamic_menu.rb', line 4 def name @name end |
- (Object) target (readonly)
Returns the value of attribute target
6 7 8 |
# File 'lib/dynamic_menu.rb', line 6 def target @target end |
Instance Method Details
- (Object) [](attribute)
8 |
# File 'lib/dynamic_menu.rb', line 8 def [](attribute); instance_variable_get("@#{attribute}".to_sym); end |
- (Object) []=(attribute, value)
9 |
# File 'lib/dynamic_menu.rb', line 9 def []=(attribute, value); instance_variable_set("@#{attribute}".to_sym, value); end |
- (Boolean) active?
21 |
# File 'lib/dynamic_menu.rb', line 21 def active?; @active; end |
- (Object) active_item
22 |
# File 'lib/dynamic_menu.rb', line 22 def active_item; self.items.find { |item| item.active? }; end |
- (Object) add(*args, &block)
16 17 18 19 |
# File 'lib/dynamic_menu.rb', line 16 def add(*args, &block) item = DynamicMenu.new(self, *args, &block) @items.push item end |
- (Object) next
25 26 27 28 |
# File 'lib/dynamic_menu.rb', line 25 def next return nil if self[:parent].items.last == self self[:parent].items.at(self.position + 1) end |
- (Object) position
23 |
# File 'lib/dynamic_menu.rb', line 23 def position; self[:parent].items.index(self); end |
- (Object) previous Also known as: prev
30 31 32 33 |
# File 'lib/dynamic_menu.rb', line 30 def previous return nil if self[:parent].items.first == self self[:parent].items.at(self.position - 1) end |
- (Object) self_or_inherited_attribute(attribute)
11 12 13 14 |
# File 'lib/dynamic_menu.rb', line 11 def self_or_inherited_attribute(attribute) attribute = attribute.to_sym self[attribute] or (self[:parent] and self[:parent].self_or_inherited_attribute(attribute)) or nil end |