class Watir::Generator::Base::SpecExtractor
Constants
- IDL_SELECTOR
Public Class Methods
new(uri)
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 9 def initialize(uri) @uri = uri end
Public Instance Methods
errors()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 24 def errors @errors ||= [] end
fetch_interface(interface)
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 45 def fetch_interface(interface) @interfaces_by_name[interface] || raise(InterfaceNotFound, "#{interface} not found in IDL") end
print_hierarchy()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 40 def print_hierarchy process if @interfaces.nil? idl_sorter.print end
process()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 13 def process download_and_parse extract_idl_parts extract_interface_map drop_issued_interfaces build_result rescue StandardError p errors raise end
sorted_interfaces()
click to toggle source
returns a topoligically sorted array of WebIDL::Ast::Interface objects
# File lib/watir/generator/base/spec_extractor.rb, line 32 def sorted_interfaces process if @interfaces.nil? idl_sorter.sort.map { |name| @interfaces.find { |i| i.name == name } || puts("ignoring interface: #{name}") }.compact end
Private Instance Methods
apply_implements(implements)
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 104 def apply_implements(implements) implements.each do |is| implementor_name = is.implementor.gsub(/^::/, '') implementee_name = is.implementee.gsub(/^::/, '') begin intf = fetch_interface(implementor_name).first intf.implements << fetch_interface(implementee_name).first rescue InterfaceNotFound => e puts e.message end end end
apply_includes(includes)
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 118 def apply_includes(includes) includes.each do |is| includer_name = is.includer.gsub(/^::/, '') includee_name = is.includee.gsub(/^::/, '') begin intf = fetch_interface(includer_name).first intf.includes << fetch_interface(includee_name).first rescue InterfaceNotFound => e puts e.message end end end
build_result()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 89 def build_result raise NotImplementedError end
download_and_parse()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 51 def download_and_parse File.open(@uri) { |io| @doc = Nokogiri.HTML(io) } end
drop_issued_interfaces()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 83 def drop_issued_interfaces @interface_map.delete_if do |_, interface| issued_interfaces.include?(interface) end end
extract_idl_parts()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 55 def extract_idl_parts parsed = @doc.search(IDL_SELECTOR).map { |e| parse_idl(e.inner_text) }.compact implements = [] includes = [] @interfaces = [] parsed.flatten.each do |element| case element when WebIDL::Ast::Interface @interfaces << element when WebIDL::Ast::ImplementsStatement implements << element when WebIDL::Ast::IncludesStatement includes << element end end @interfaces_by_name = @interfaces.group_by(&:name) apply_implements(implements) apply_includes(includes) merge_interfaces end
extract_interface_map()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 79 def extract_interface_map raise NotImplementedError end
idl_parser()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 146 def idl_parser @idl_parser ||= WebIDL::Parser::IDLParser.new end
idl_sorter()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 150 def idl_sorter @idl_sorter ||= Base::IDLSorter.new(@interfaces) end
merge_interfaces()
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 132 def merge_interfaces non_duplicates = @interfaces.uniq(&:name) duplicates = @interfaces - non_duplicates duplicates.each do |intf| final = non_duplicates.find { |i| i.name == intf.name } final.inherits += intf.inherits final.members += intf.members final.extended_attributes += intf.extended_attributes end @interfaces = non_duplicates end
parse_idl(str)
click to toggle source
# File lib/watir/generator/base/spec_extractor.rb, line 93 def parse_idl(str) result = idl_parser.parse(str) if result result.build else errors << idl_parser.failure_reason nil end end