Sha256: 05c70421cbe18d443c39980c0e99977582fad1dad2cf81894277755c4f0d6909

Contents?: true

Size: 564 Bytes

Versions: 3

Compression:

Stored size: 564 Bytes

Contents

require 'open-uri'
require 'cgi'
require 'nokogiri'

module PageRankr
  class Ranks < Tracker
    class Alexa < Rank
      def initialize(site)
        @rank = {}
        xpath.each_key do |key|
          @rank[key] = Nokogiri::HTML(open(url(site))).search(xpath[key]).to_s.to_i
        end
        @rank
      end
      
      def xpath
        { :us     => "//reach/@rank", 
          :global => "//popularity/@text" }
      end
      
      def url(site)
        "http://data.alexa.com/data?cli=10&dat=snbamz&url=#{CGI.escape(site)}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
PageRankr-1.7.1 lib/page_rankr/ranks/alexa.rb
PageRankr-1.7.0 lib/page_rankr/ranks/alexa.rb
PageRankr-1.6.0 lib/page_rankr/ranks/alexa.rb