Sha256: 3c9f618b74ad981e71f4a2985fedf260480273da9a3ed6e838f1fd04d39c7da6

Contents?: true

Size: 984 Bytes

Versions: 57

Compression:

Stored size: 984 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

57 entries across 57 versions & 2 rubygems

Version Path
watir-webdriver-0.6.9 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.8 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.7 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.6 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.5 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.4 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.3 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.2 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.1 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.6.0 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.8 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.7 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.6 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.5 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.4 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.3 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.2 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.1 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.5.0 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.4.1 lib/watir-webdriver/html/idl_sorter.rb