Sha256: 3e44f2d0b9cc398c03e189762ff3c50d18968e78d01a8f575aa8008f12cc0959
Contents?: true
Size: 1.79 KB
Versions: 2
Compression:
Stored size: 1.79 KB
Contents
require 'nokogiri' require 'open-uri' require 'zomg' require 'activesupport' doc = Nokogiri::HTML(open('http://w3c-test.org/webperf/specs/NavigationTiming/')) # https://w3c-test.org/navigation-timing/ idl = [] doc.css('pre.idl').each do |content| idl << content.text end nodes = [] idl.each do |spec| nodes << ZOMG::IDL.parse(spec) unless ZOMG::IDL.parse(spec).nil? end results = {} results[:class] = 'Performance' results[:interfaces] = {} nodes.each do |node| interface_name = node.children.first.header.name.gsub('Performance', '') results[:interfaces][interface_name] = {} results[:interfaces][interface_name][:attrs] = [] results[:interfaces][interface_name][:constants] = {} node.children.first.children.each do |child| case child.class.to_s when 'ZOMG::IDL::Nodes::Attribute' results[:interfaces][interface_name][:attrs] << child.children.first.name.underscore when 'ZOMG::IDL::Nodes::Constant' consts = results[:interfaces][interface_name][:constants] consts[child.name] = child.children.children end end end open(File.expand_path(File.dirname(__FILE__)) + "/#{results[:class].underscore}.rb", 'w') do |f| f.puts '# auto-generated by idl_extractor.rb' f.puts "class #{results[:class]}" results[:interfaces].each_key do |interface_name| f.puts ' ' * 2 + "class #{interface_name}" results[:interfaces][interface_name][:constants].each do |k, v| f.puts ' ' * 4 + "#{k} = #{v.to_i}" end f.puts ' ' * 4 + 'attr_reader ' + results[:interfaces][interface_name][:attrs].collect! {|x| ":"+x}.join(", ") f.puts <<-'eos' def initialize(args) args.each do |k,v| instance_variable_set("@#{k}", v) if respond_to?(k.to_sym) unless v.nil? end end eos f.puts ' ' * 2 + 'end' end f.puts 'end' end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
watir-performance-0.9.0 | lib/idl_extractor.rb |
watir-performance-0.8.0 | lib/idl_extractor.rb |