require 'open-uri' class Page attr_reader :url, :source, :name def initialize(url) @name = Time.new.to_i.to_s + '_' + rand(9999).to_s @url = URI.parse(url) @source = open(url).readlines end def to_s <<-EOS.gsub(/^\s+\|\s/, '') | http.page_start("#{name}") | http.request_batch({ | {"GET", "#{url}", auto_decompress=true} | }) | | http.request_batch({ | #{asset_include.join("\n")} | }) | | http.page_end("#{name}") | | EOS end def assets @source.map do |l| l =~ /(?:\s|data-)?src="(.*?)"/ $1 if $1 end.compact.select do |l| l.include?(url.host) end end def asset_include assets.map do |url| ' {"GET", "' + url + '", auto_decompress=true},' end end end