Class: SearchProviders

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

Class Method Summary collapse

Class Method Details

.bing(keyword) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/search.rb', line 8

def self.bing(keyword)
  res =  RestClient.get 'https://bing.com/search/', params: { q: keyword }
  tags = Nokogiri::HTML.parse(res).xpath('//li[@class="b_algo"] //h2 //a')
  tags.each do |tag|
    Display.tags tag
  end
end

.gems(keyword) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/search.rb', line 16

def self.gems(keyword)
  res = RestClient.get "https://rubygems.org/search?utf8=%E2%9C%93&query=#{keyword}"
  tags = Nokogiri::HTML.parse(res).xpath('//a[@class="gems__gem"]')
  tags.each do |tag|
    Display.tags tag
  end
end

.help(_noarg = nil) ⇒ Object



34
35
36
# File 'lib/search.rb', line 34

def self.help(_noarg = nil)
  Display.help!
end

.so(keyword) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/search.rb', line 24

def self.so(keyword)
  Display.before_result
  res = RestClient.get "https://stackoverflow.com/search?q=#{keyword}"
  tags = Nokogiri::HTML.parse(res).xpath('//a[@class="question-hyperlink"]')
  tags.each do |tag|
    Display.tags tag
  end
  Display.after_result
end