Sha256: c18d0350d9e68580611685f8d2444d3ffab88f28c4122a0cae90840ca22379fc

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

module Watir
  module Generator
    class SVG::SpecExtractor < Base::SpecExtractor

      private

      def extract_interface_map
        list = @doc.search("//div[@id='chapter-eltindex']//ul/li")
        list.any? or raise 'could not find elements list'

        @interface_map = parse_list(list)
      end

      def build_result
        {}.tap do |result|
          @interface_map.each do |tag, interface|
            result[tag] = fetch_interface(interface)
          end
        end
      end

      def parse_list(list)
        {}.tap do |result|
          list.each do |node|
            tag_name = node.css('a span').inner_text.strip
            id = node.css('a').attr('href').to_s

            next if external_interface?(id)

            interface_css = 'div.element-summary a.idlinterface'
            interface_definitions = @doc.css("#{id} #{interface_css}, #{id} ~ #{interface_css}")

            # TSpan is defined along with Text so the first IDL definition is SVGTextElement
            idx = tag_name == 'tspan' ? 1 : 0

            result[tag_name] = interface_definitions[idx].inner_text.strip
          end
        end
      end

      def issued_interfaces
        %w(SVGHatchElement SVGHatchPathElement SVGSolidColorElement)
      end

      # Some interfaces are actually defined in different specs
      # (for example, clipPath), so we ignore them for now.
      def external_interface?(id)
        id !~ /^#.+/
      end

    end # SVG::SpecExtractor
  end # Generator
end # Watir

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-6.10.1 lib/watir/generator/svg/spec_extractor.rb