Class: QuickCite::DBLP
- Inherits:
-
Object
- Object
- QuickCite::DBLP
- Defined in:
- lib/quickcite/dblp.rb
Constant Summary collapse
- SEARCH_BASE =
NB – DBLP seems to expect query arguments in a certain order - the q= argument has to come first.
"http://www.dblp.org/search/api/?"- SEARCH_SUFFIX =
"&c=4&f=0&format=json&h=10"
Instance Method Summary collapse
Instance Method Details
#bibtex(result) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/quickcite/dblp.rb', line 60 def bibtex(result) # dom = Nokogiri.Slop(open("test/power-piccolo.html")) dom = Nokogiri.Slop Net::HTTP.get(URI::parse(result.url)) entries = dom.html.body.pre case entries when Nokogiri::XML::NodeSet return entries[0].to_str else return entries.to_str end end |
#hit_to_result(h) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/quickcite/dblp.rb', line 19 def hit_to_result(h) t = h["title"] title = t["dblp:title"]["text"] venue = t["dblp:venue"]["text"] = t["dblp:authors"]["dblp:author"] date = t["dblp:year"].to_s Result.new( :title => title, :authors => .to_a, :url => h["url"], :venue => venue, :date => date) end |
#search(query) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/quickcite/dblp.rb', line 33 def search(query) #json = JSON.parse(File.read("test/foobar.json")) query_str = "q=" + URI::escape(query.join(" ")) uri = URI::parse(SEARCH_BASE + query_str + SEARCH_SUFFIX) puts("Fetching from #{uri}") response = Net::HTTP::get(uri) json = JSON.parse(response) hit_count = json["result"]["hits"]["@sent"]; if hit_count == 0 then [] end hits = json["result"]["hits"]["hit"] # NB. when there is only a single result DBLP returns a single # hit element instead of an array. case hits when Array hits.map { |h| hit_to_result(h) } else [hit_to_result(hits)] end end |