Class: GovKit::SearchEngines::Wikipedia

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gov_kit/search_engines/wikipedia.rb

Class Method Summary collapse

Class Method Details

.make_request(host, path) ⇒ Object



22
23
24
# File 'lib/gov_kit/search_engines/wikipedia.rb', line 22

def self.make_request(host, path)
  response = Net::HTTP.get(host, path)
end

.search(query, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gov_kit/search_engines/wikipedia.rb', line 9

def self.search(query, options={})
  doc = Nokogiri::HTML(get("/wiki/#{query}"))

  bio = doc.at('#bodyContent > p:first').text rescue ""

  # Convert HTML => text.
  # bio = Loofah.fragment(bio).text

  return "" if bio =~ /may refer to:/

  bio
end