Sha256: 68a3323ea9071ef45d6ed5b6f4272d434c52aba2927e1a7aea5f9abae450050f

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'tsort'

module Watir
  module Generator
    class Base::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 # Generator
end # Watir

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-6.10.1 lib/watir/generator/base/idl_sorter.rb