lib/page_rankr/backlink.rb in PageRankr-1.7.1 vs lib/page_rankr/backlink.rb in PageRankr-2.0.0

- old
+ new

@@ -1,15 +1,21 @@ require 'rubygems' require 'nokogiri' require 'open-uri' module PageRankr - class Backlink + module Backlink attr_reader :backlinks alias_method :tracked, :backlinks def initialize(site) - @backlinks = clean Nokogiri::HTML(open url(site)).at(xpath).to_s + @site = site + + request.on_complete do |response| + html = Nokogiri::HTML(response.body) + @backlinks = clean(html.at(xpath).to_s) + @backlinks = nil if @backlinks.zero? + end end def clean(backlink_count) backlink_count.gsub(/[a-zA-Z,\s\(\)]/, '').to_i end \ No newline at end of file