lib/load_impact/page.rb in load_impact-0.0.2 vs lib/load_impact/page.rb in load_impact-0.0.3

- old
+ new

@@ -1,12 +1,10 @@ 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 @@ -27,19 +25,19 @@ | 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 + @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 \ No newline at end of file +end