Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11 from FND/title_extraction

add method to retrieve page title
  • Loading branch information...
commit 9e8e86d16f7c50b4dd87de3537a9d6205a81f58e 2 parents 15cb43c + 3f030a8
@iterationlabs iterationlabs authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.