Permalink
Browse files

`Scraper#parse` overrides any value that singular properties might ha…

…ve had
  • Loading branch information...
mislav committed Dec 10, 2009
1 parent a6fe12b commit 74faea84fd9914f83eb971e34b6f9f605f6d2aa6
Showing with 11 additions and 3 deletions.
  1. +11 −3 scraper.rb
View
@@ -35,8 +35,8 @@ def parse
@doc.search(selector).each do |node|
send(target) << parse_result(node, delegate)
end
- elsif node = @doc.at(selector)
- send("#{target}=", parse_result(node, delegate))
+ else
+ send("#{target}=", parse_result(@doc.at(selector), delegate))
end
end
self
@@ -52,7 +52,7 @@ def parse_result(node, delegate)
node.inner_text
else
node.to_s
- end
+ end unless node.nil?
end
private
@@ -195,6 +195,14 @@ def search(selector)
article.published.should == 'Sep 5'
article.link.should == 'http://mislav.uniqpath.com'
end
+
+ it "should override singular properties when re-parsing" do
+ blog = @blog.dup
+ blog.instance_variable_set('@doc', Nokogiri::HTML(''))
+ blog.parse
+ blog.title.should be_nil
+ blog.should have(2).articles
+ end
end
describe SpecialArticle do

0 comments on commit 74faea8

Please sign in to comment.