HtmlPageTitle

gem install html_page_title

A simple class for finding the title of a given http url by fetching the given url, following all eventual redirects and finally parsing it through hpricot.

You can either use the shorthand form or initialize the instance properly:

* HtmlPageTitle('http://github.com')
* HtmlPageTitle.new('http://github.com')

Those calls are equivalent, except for one subtle difference: The shorthand form will swallow SocketErrors and return nil (i.e. this will happen for invalid urls), while the regular instantiation via new will throw that error.

You can either get the title, the heading (which will be the content of the first h1 tag in the body) or the label, which will be (in the following order by availability) either the heading, or the title, or the target url after redirecting. Note that if the title or the heading can not be found (e.g. a non-HTML document), both methods will return nil, so the label method is the only one that will always return some kind of string

You can also have a look at the unit test to find out about the behaviour!

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Christoph Olszowka. See LICENSE for details.