Class: SeoParams::Google

Inherits:
Object
  • Object
show all
Defined in:
lib/seo_params/google.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Google

Returns a new instance of Google.



15
16
17
18
# File 'lib/seo_params/google.rb', line 15

def initialize(url)
  @url = url
  @host = get_host
end

Instance Method Details

#google_pagesObject



26
27
28
29
30
# File 'lib/seo_params/google.rb', line 26

def google_pages
  doc = Nokogiri::HTML(open("https://www.google.com/search?hl=en&tab=ww&safe=active&tbo=d&sclient=psy-ab&q=site:#{@url}&oq=site:#{@url}"))
  pages = doc.css('div[@id="resultStats"]').to_s[/[\d,]+/] if doc.css('div[@id="subform_ctrl"]')
  pages ? pages.tr(',', '').to_i : 0
end

#google_position(hl, cr, keywords, num) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/seo_params/google.rb', line 32

def google_position(hl, cr, keywords, num)

  h = Hash.new

  EventMachine.synchrony do

    EM::Synchrony::FiberIterator.new(keywords, keywords.size).each do |keyword|

      new_keyword = check_keyword(keyword)

      uri="http://www.google.com/search?hl=#{hl}&q=#{new_keyword}&btnG=Поиск+в+Google&&cr=#{cr}&meta=&num=#{num}"
      resp = EventMachine::HttpRequest.new(uri).get
      h[keyword] = parse_results resp.response
    end
    EventMachine.stop
  end

  h

end

#pagerankObject



21
22
23
24
# File 'lib/seo_params/google.rb', line 21

def pagerank
  query = PageRankr.ranks(@url, :google)
  query[:google]
end