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.4.0 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.9 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.8 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.7 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.6 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.5 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.4 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.3 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.2 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.1 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.3.0 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.9 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.8 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.7 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.6 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.5 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.4 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.3 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.2 lib/watir-webdriver/html/idl_sorter.rb
watir-webdriver-0.2.1 lib/watir-webdriver/html/idl_sorter.rb