Class: WonderNavigation::MenuEntry
- Inherits:
-
Object
- Object
- WonderNavigation::MenuEntry
- Defined in:
- lib/wonder_navigation/menu_entry.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#children ⇒ Object
Returns the value of attribute children.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#id ⇒ Object
Returns the value of attribute id.
-
#label ⇒ Object
Returns the value of attribute label.
-
#level ⇒ Object
Returns the value of attribute level.
-
#path ⇒ Object
Returns the value of attribute path.
-
#visible ⇒ Object
Returns the value of attribute visible.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #has_active_children? ⇒ Boolean
- #has_visible_children? ⇒ Boolean
-
#initialize(id, level) ⇒ MenuEntry
constructor
A new instance of MenuEntry.
- #promote_active_state ⇒ Object
- #visible_children ⇒ Object
Constructor Details
#initialize(id, level) ⇒ MenuEntry
Returns a new instance of MenuEntry.
4 5 6 7 8 |
# File 'lib/wonder_navigation/menu_entry.rb', line 4 def initialize(id, level) @id = id @level = level @children = [] end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def active @active end |
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def children @children end |
#icon ⇒ Object
Returns the value of attribute icon.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def icon @icon end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def id @id end |
#label ⇒ Object
Returns the value of attribute label.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def label @label end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def level @level end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def path @path end |
#visible ⇒ Object
Returns the value of attribute visible.
3 4 5 |
# File 'lib/wonder_navigation/menu_entry.rb', line 3 def visible @visible end |
Class Method Details
.level_class(level) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/wonder_navigation/menu_entry.rb', line 30 def self.level_class(level) classes = { 2 => "second", 3 => "third" } classes[level] end |
Instance Method Details
#active? ⇒ Boolean
10 11 12 |
# File 'lib/wonder_navigation/menu_entry.rb', line 10 def active? active || children.any?(&:active?) end |
#has_active_children? ⇒ Boolean
18 19 20 |
# File 'lib/wonder_navigation/menu_entry.rb', line 18 def has_active_children? children.any?(&:active) end |
#has_visible_children? ⇒ Boolean
14 15 16 |
# File 'lib/wonder_navigation/menu_entry.rb', line 14 def has_visible_children? children.any?(&:visible) end |
#promote_active_state ⇒ Object
22 23 24 |
# File 'lib/wonder_navigation/menu_entry.rb', line 22 def promote_active_state self.active ||= has_active_children? end |
#visible_children ⇒ Object
26 27 28 |
# File 'lib/wonder_navigation/menu_entry.rb', line 26 def visible_children children.select(&:visible) end |