Class: PartialMenu::MenuItem

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
lib/partial_menu/menu_item.rb

Overview

Represents menu item in a menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props, parent) ⇒ MenuItem

Contructor which check parameter types and start setup

Throws ArgumentError if parameters are not expected type

Parameters:

  • props (Hash)

    The menu list propertiess from the yaml file.

  • parent (PartialMenu::Menu)

    The parent Menu of the item



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

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/partial_menu/menu_item.rb', line 11

def id
  @id
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/partial_menu/menu_item.rb', line 12

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/partial_menu/menu_item.rb', line 7

def parent
  @parent
end

Returns the value of attribute submenu.



10
11
12
# File 'lib/partial_menu/menu_item.rb', line 10

def submenu
  @submenu
end

#titleObject (readonly)

Returns the value of attribute title.



9
10
11
# File 'lib/partial_menu/menu_item.rb', line 9

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/partial_menu/menu_item.rb', line 6

def type
  @type
end

#uriObject (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

Returns:

  • (Boolean)


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

Returns:

  • (boolean)


48
49
50
# File 'lib/partial_menu/menu_item.rb', line 48

def separator?
  @type == :separator
end

True if menu item has submenu

Returns:

  • (boolean)


39
40
41
# File 'lib/partial_menu/menu_item.rb', line 39

def submenu?
  @submenu != nil
end