Skip to content
Browse files

add method to retrieve page title

  • Loading branch information...
1 parent 15cb43c commit 3f030a8a5daa1cdf9195552df84a23a3afd20dda FND committed Aug 10, 2011
Showing with 13 additions and 0 deletions.
  1. +5 −0 lib/readability.rb
  2. +8 −0 spec/readability_spec.rb
View
5 lib/readability.rb
@@ -43,6 +43,11 @@ def make_html
:videoRe => /http:\/\/(www\.)?(youtube|vimeo)\.com/i
}
+ def title
+ title = @html.css("title").first
+ title ? title.text : nil
+ end
+
def content(remove_unlikely_candidates = :default)
@remove_unlikely_candidates = false if remove_unlikely_candidates == false
View
8 spec/readability_spec.rb
@@ -166,6 +166,14 @@
it "should return the main page content" do
@doc.content.should match("Some content")
end
+
+ it "should return the page title if present" do
+ @doc.title.should match("title!")
+
+ doc = Readability::Document.new("<html><head></head><body><div><p>Some content</p></div></body>",
+ :min_text_length => 0, :retry_length => 1)
+ doc.title.should be_nil
+ end
end
describe "ignoring sidebars" do

0 comments on commit 3f030a8

Please sign in to comment.
Something went wrong with that request. Please try again.