Module: GoogleScholar
- Defined in:
- lib/rbbt/sources/gscholar.rb
Class Method Summary collapse
- .citation_link(title) ⇒ Object
- .full_text_url(title) ⇒ Object
- .number_cites(title) ⇒ Object
- .user_agent ⇒ Object
Class Method Details
.citation_link(title) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rbbt/sources/gscholar.rb', line 8 def self.citation_link(title) citation_link = nil # Get citation page user_agent.get("http://scholar.google.es/scholar?q='#{ title }'&hl=es&lr=&lr=") do |page| article = page.search('div[@class=gs_r]').first return nil if article.nil? return article.search('a').select{|link| link['href'] =~ /scholar\?cites/ && link.inner_html =~ /\d+$/ }.first end end |
.full_text_url(title) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbbt/sources/gscholar.rb', line 20 def self.full_text_url(title) full_text_link = nil # Get page user_agent.get("http://scholar.google.es/scholar?q='#{ title }'&hl=es&lr=&lr=") do |page| article = page.search('div[@class=gs_r]').first return nil if article.nil? link = article.search('a').select{ |link| link['href'] =~ /\.pdf$/ || link['href'] =~ /type=pdf/ }.first return nil if link.nil? return link['href'] end end |
.number_cites(title) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rbbt/sources/gscholar.rb', line 39 def self.number_cites(title) link = citation_link title return 0 if link.nil? link.inner_html =~ /(\d+)$/ return $1.to_i end |
.user_agent ⇒ Object
4 5 6 |
# File 'lib/rbbt/sources/gscholar.rb', line 4 def self.user_agent @@a ||= Mechanize.new end |