module PageRankr::Tracker
Attributes
body[RW]
raw[RW]
tracked[RW]
Public Class Methods
new(site, options = {})
click to toggle source
# File lib/page_rankr/tracker.rb, line 14 def initialize(site, options = {}) @site = PageRankr::Site(site) @options = options # Initialize proxy, so threads don't need to synchronize the proxy service. proxy end
Public Instance Methods
clean(content)
click to toggle source
# File lib/page_rankr/tracker.rb, line 64 def clean(content) cleaned_content = content.to_s.gsub(/\D/, '') if cleaned_content.strip == '' nil else cleaned_content.to_i end end
content(body)
click to toggle source
# File lib/page_rankr/tracker.rb, line 52 def content(body) if respond_to? :xpath Nokogiri::HTML(body).at(xpath) elsif respond_to? :jsonpath JsonPath.new(jsonpath).first(JSON.parse(body)) elsif respond_to? :regex body =~ regex ? $1 : nil else raise PageRankr::MethodRequired, "A method for extracting the value must be defined. Either xpath, jsonpath, or regex." end.to_s end
method()
click to toggle source
# File lib/page_rankr/tracker.rb, line 34 def method :get end
name()
click to toggle source
# File lib/page_rankr/tracker.rb, line 74 def name raise PageRankr::MethodRequired, "name is undefined for #{self.class.name}" end
proxy()
click to toggle source
# File lib/page_rankr/tracker.rb, line 38 def proxy @proxy ||= URI.parse(PageRankr.proxy_service.proxy(name, @site)) if PageRankr.proxy_service end
run()
click to toggle source
# File lib/page_rankr/tracker.rb, line 42 def run PageRankr::Request.new(self, @options).perform do |body| self.body = body self.raw = content(body) self.tracked = clean(raw) end tracked end
supported_components()
click to toggle source
# File lib/page_rankr/tracker.rb, line 30 def supported_components [:subdomain] end
tracked_url()
click to toggle source
# File lib/page_rankr/tracker.rb, line 26 def tracked_url @site.url(supported_components) end
url()
click to toggle source
# File lib/page_rankr/tracker.rb, line 22 def url raise PageRankr::MethodRequired, "A url method defining the url to the service with the value you wish to extract must be defined." end