Module: PageRankr::Tracker
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#tracked ⇒ Object
Returns the value of attribute tracked.
Instance Method Summary collapse
- #clean(content) ⇒ Object
- #content(body) ⇒ Object
- #initialize(site, options = {}) ⇒ Object
- #method ⇒ Object
- #name ⇒ Object
- #proxy ⇒ Object
- #run ⇒ Object
- #supported_components ⇒ Object
- #tracked_url ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
12 13 14 |
# File 'lib/page_rankr/tracker.rb', line 12 def body @body end |
#raw ⇒ Object
Returns the value of attribute raw.
11 12 13 |
# File 'lib/page_rankr/tracker.rb', line 11 def raw @raw end |
#tracked ⇒ Object
Returns the value of attribute tracked.
10 11 12 |
# File 'lib/page_rankr/tracker.rb', line 10 def tracked @tracked end |
Instance Method Details
#clean(content) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# 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) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# 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 |
#initialize(site, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/page_rankr/tracker.rb', line 14 def initialize(site, = {}) @site = PageRankr::Site(site) @options = # Initialize proxy, so threads don't need to synchronize the proxy service. proxy end |
#method ⇒ Object
34 35 36 |
# File 'lib/page_rankr/tracker.rb', line 34 def method :get end |
#name ⇒ Object
74 75 76 |
# File 'lib/page_rankr/tracker.rb', line 74 def name raise PageRankr::MethodRequired, "name is undefined for #{self.class.name}" end |
#proxy ⇒ Object
38 39 40 |
# 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 ⇒ Object
42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/page_rankr/tracker.rb', line 30 def supported_components [:subdomain] end |
#tracked_url ⇒ Object
26 27 28 |
# File 'lib/page_rankr/tracker.rb', line 26 def tracked_url @site.url(supported_components) end |
#url ⇒ Object
22 23 24 |
# 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 |