Permalink
Browse files

using Hpricot for a cleaner #img method

  • Loading branch information...
1 parent c4e8852 commit 6fa75f0f829ae9be47e66fe5d17b52eb8c310cf7 Fraser Murray committed May 20, 2012
Showing with 2 additions and 5 deletions.
  1. +2 −5 lib/xkcd.rb
View
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-require 'net/http'
+require 'hpricot'
require 'open-uri'
# The main XKCD driver
class XKCD
@@ -21,9 +21,6 @@ class << XKCD
end
def self.img
- url = 'http://dynamic.xkcd.com/random/comic/'
- html = open(url).read
- imgs = URI.extract(html).select{ |l| l[/comics\//]}
- imgs.first
+ Hpricot(open('http://dynamic.xkcd.com/random/comic/')).search("#comic img").first.raw_attributes["src"]
end
end

0 comments on commit 6fa75f0

Please sign in to comment.