Class: MenuCreator::MenuBar

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap2-rails/menu_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMenuBar

Returns a new instance of MenuBar.



6
7
8
# File 'lib/bootstrap2-rails/menu_creator.rb', line 6

def initialize
  @dropdowns = []
end

Instance Attribute Details

Returns the value of attribute dropdowns.



4
5
6
# File 'lib/bootstrap2-rails/menu_creator.rb', line 4

def dropdowns
  @dropdowns
end

#projectObject

Returns the value of attribute project.



4
5
6
# File 'lib/bootstrap2-rails/menu_creator.rb', line 4

def project
  @project
end

Instance Method Details

#add_dropdown(dropdown) ⇒ Object



10
11
12
# File 'lib/bootstrap2-rails/menu_creator.rb', line 10

def add_dropdown(dropdown)
  @dropdowns << dropdown if valid_dropdown?(dropdown)
end

#valid_dropdown?(dropdown) ⇒ Boolean

Check if is a valid dropdown A valid dropdown is a class with position an caption attributes and an array of subitems

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/bootstrap2-rails/menu_creator.rb', line 17

def valid_dropdown?(dropdown)
  return false unless dropdown.position
  return false unless %W(left right).include? dropdown.position.to_s
  return false unless dropdown.caption      
  return false unless valid_subitems?(dropdown.subitems)
  true
end

#valid_subitems?(subitems) ⇒ Boolean

Check if all subitems are valid Subitem must be a hash with keys :caption, :controller and :action or a string “—” in case of a separator

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bootstrap2-rails/menu_creator.rb', line 28

def valid_subitems?(subitems)
  return false if subitems.length == 0
  subitems.each do |subitem|
    if subitem.class.to_s == "Hash"
      return false unless subitem.has_key?(:caption) && subitem.has_key?(:controller) &&
        subitem.has_key?(:action)
    else
      return false unless subitem.to_s == '---'
    end
  end
  true
end