Sha256: 0f91803a39cab96c9f7f18188eb1e3758ba9bd6c1f1b17b748b05d20871a3618

Contents?: true

Size: 986 Bytes

Versions: 3

Compression:

Stored size: 986 Bytes

Contents

# encoding: utf-8

require 'tsort'

module Watir
  module HTML
    class IDLSorter
      include TSort

      def initialize(interfaces)
        @interfaces = {}

        interfaces.each do |interface|
          @interfaces[interface.name] ||= []
          interface.inherits.each do |inherit|
            (@interfaces[inherit.name] ||= []) << interface.name
          end
        end
      end

      def print
        @visited = []
        sort.each { |node| print_node(node) }
      end

      def sort
        tsort.reverse
      end

      def tsort_each_node(&blk)
        @interfaces.each_key(&blk)
      end

      def tsort_each_child(node, &blk)
        @interfaces[node].each(&blk)
      end

      private

      def print_node(node, indent = 0)
        return if @visited.include?(node)
        @visited << node
        puts " " * indent + node
        tsort_each_child(node) { |child| print_node(child, indent + 2)}
      end

    end # IDLSorter
  end # HTML
end # Watir

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
watir-webdriver-0.7.0 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.11 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.10 lib/watir-webdriver/html/idl_sorter.rb