<commit_before>#Copyright (c) 2010, <NAME>. All rights reserved.

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

      def root_menu_item_names
        root_menu_items.collect {|menu_item| menu_item.name}
      end
          
      def select_menu(path)
        menu_item(path).click
      end

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

      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

      def contains_menu_item?(path)
        begin
          menu_item(path)
          return true
        rescue ElementDoesntExist => e
          return false
        end
      end
    end
  end
end<commit_msg>adding rdoc to menu additions<commit_after>#Copyright (c) 2010, <NAME>. All rights reserved.

module Bewildr
  module ControlTypeAdditions
    module MenuAdditions
      #Returns an array containing the menu's root items
      def root_menu_items
        get(:type => :menu_item, :scope => :children, :how_many => :all)
      end

      #Returns a string array containing the root items' names
      def root_menu_item_names
        root_menu_items.collect {|menu_item| menu_item.name}
      end

      #Clicks the menu described by the input, eg:
      #  select_menu(["File", "Close"])
      def select_menu(path)
        menu_item(path).click
      end

      #Selects the menu described by the input, eg:
      #  select_node(["File", "Close"])
      def select_node(path)
        node(path).select
      end

      #Returns the menu item described by the input, eg:
      #  menu_item(["File", "Close"])
      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

      #Returns true if the menu contains the item described by the input, false if it doesn't
      def contains_menu_item?(path)
        begin
          menu_item(path)
          return true
        rescue ElementDoesntExist => e
          return false
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0624048706240487, 'fraction_numerical': 0.0025367833587011668, 'mean_word_length': 2.1619887730553327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7584667', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1112, 'n_words': 313}