require 'open-uri' class Page attr_reader :url, :source, :name URL = /(?:https?:\/\/)(?:[\da-z\.-]+)\.(?:[a-z\.]{2,6})(?:[\/\w \.-]*)\/?/ 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 matcher = /.*#{url.host}.*(js|css|png|jpg|jpeg|gif)/i @source.select { |line| URL.match(line) }. map { |line| URL.match(line)[0] }. select { |line| matcher.match(line) }. uniq. sort end def asset_include assets.map do |url| ' {"GET", "' + url + '", auto_decompress=true},' end end end