Module: Bewildr::ControlTypeAdditions::MenuAdditions

Defined in:
lib/bewildr/control_type_additions/menu_additions.rb

Instance Method Summary collapse

Instance Method Details

#contains_menu_item?(path) ⇒ Boolean

Returns true if the menu contains the item described by the input, false if it doesn’t

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 55

def contains_menu_item?(path)
  begin
    menu_item(path)
    return true
  rescue ElementDoesntExist => e
    return false
  end
end

Returns the menu item described by the input, eg:

menu_item(["File", "Close"])


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 30

def menu_item(path)
  current_menu_items = root_menu_items
  matching_menu_item = nil
  path.each_with_index do |target_menu_item, index|
    case current_menu_items
    when Array
      matching_menu_item = current_menu_items.find {|node| node.name == target_menu_item} #TODO: make this work with regexes as well as strings...
      raise Bewildr::ElementDoesntExist if matching_menu_item.nil?
    when Bewildr::Element
      if current_menu_items.name == target_menu_item #TODO: make this work with regexes as well as strings...
        matching_menu_item = current_menu_items
      else
        raise Bewildr::ElementDoesntExist
      end
    end
    raise Bewildr::ElementDoesntExist if matching_menu_item.nil?
    if path.size != index + 1
      matching_menu_item.expand
      current_menu_items = matching_menu_item.sub_menus
    end
  end
  return matching_menu_item
end

#root_menu_item_namesObject

Returns a string array containing the root items’ names



12
13
14
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 12

def root_menu_item_names
  root_menu_items.collect {|menu_item| menu_item.name}
end

#root_menu_itemsObject

Returns an array containing the menu’s root items



7
8
9
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 7

def root_menu_items
  get(:type => :menu_item, :scope => :children, :how_many => :all)
end

#select_menu(path) ⇒ Object

Clicks the menu described by the input, eg:

select_menu(["File", "Close"])


18
19
20
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 18

def select_menu(path)
  menu_item(path).click
end

#select_node(path) ⇒ Object

Selects the menu described by the input, eg:

select_node(["File", "Close"])


24
25
26
# File 'lib/bewildr/control_type_additions/menu_additions.rb', line 24

def select_node(path)
  node(path).select
end