Q:

Use Tempfile twice?

I'm having an issue with a simple program over what I believe has to do with Tempfiles. I am using 'open-uri' and 'nokogiri' and am trying to do a regex search on a document as well as an xpath search with nokogiri. However, it seems I cannot do this without making two seperate requests for the document and thus creating two separate Tempfiles. This works, but is making two requests:
require 'open-uri'
require 'nokogiri'

source_url = "http://foo.com/"
#grab html document and assign it a variable
doc = open(source_url)
#grab html document, convert to Nokogiri object and assign to variable.
noko_doc = Nokogiri::HTML(open(source_url))

#create array of stuff. 
foo = noko_doc.xpath("//some element").collect { |e| e }
#create another array of stuff
bar = []
doc.each do |f|
    f.each do |line|
        abstract_matches = line.scan(/some regex string/)                                  
        unless abstract_matches.empty?
            abstract_matches.collect! do |item|
                if item.to_s.match(/yet another regex string/) 
                    item
                end
            end.compact!
            unless abstract_matches.empty?
                abstract_matches.each { |match| bar << "#{ match } / " }
            end
        end
    end
end
#all for this
puts foo + bar

I would prefer if I could pass the 'doc' variable into Nokogiri::HTML, as well as iterate over it. Help?

A:

It's uncommon to iterate a Tempfile. More common is to access like this:
html = open(source_url).read
noko_doc = Nokogiri::HTML(html)
html.split("\n").each do |line|
  # do stuff
end

