Class: PartialMenu::MenuItem
- Inherits:
-
Object
- Object
- PartialMenu::MenuItem
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- lib/partial_menu/menu_item.rb
Overview
Represents menu item in a menu
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#submenu ⇒ Object
readonly
Returns the value of attribute submenu.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#active?(view) ⇒ Boolean
True if current url relates to the menu item’s uri.
-
#initialize(props, parent) ⇒ MenuItem
constructor
Contructor which check parameter types and start setup.
-
#separator? ⇒ boolean
True if menu item is a separator.
-
#submenu? ⇒ boolean
True if menu item has submenu.
Constructor Details
#initialize(props, parent) ⇒ MenuItem
Contructor which check parameter types and start setup
Throws ArgumentError if parameters are not expected type
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/partial_menu/menu_item.rb', line 22 def initialize(props, parent) unless props.is_a? Hash raise ::ArgumentError, "Expected Hash, got #{prop.class}" end unless parent.is_a? PartialMenu::Menu raise ::ArgumentError, "Expected PartialMenu::Menu, got #{parent.class}" end @parent = parent @props = props setup end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/partial_menu/menu_item.rb', line 11 def id @id end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/partial_menu/menu_item.rb', line 12 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/partial_menu/menu_item.rb', line 7 def parent @parent end |
#submenu ⇒ Object (readonly)
Returns the value of attribute submenu.
10 11 12 |
# File 'lib/partial_menu/menu_item.rb', line 10 def @submenu end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/partial_menu/menu_item.rb', line 9 def title @title end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/partial_menu/menu_item.rb', line 6 def type @type end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/partial_menu/menu_item.rb', line 8 def uri @uri end |
Instance Method Details
#active?(view) ⇒ Boolean
True if current url relates to the menu item’s uri
59 60 61 |
# File 'lib/partial_menu/menu_item.rb', line 59 def active?(view) view.current_page? view.url_for @uri end |
#separator? ⇒ boolean
True if menu item is a separator
48 49 50 |
# File 'lib/partial_menu/menu_item.rb', line 48 def separator? @type == :separator end |
#submenu? ⇒ boolean
True if menu item has submenu
39 40 41 |
# File 'lib/partial_menu/menu_item.rb', line 39 def @submenu != nil end |