google_scholar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in google_scholar.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "google_scholar/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "google_scholar"
7
+ s.version = GoogleScholar::VERSION
8
+ s.authors = ["Antonio Tapiador del Dujo"]
9
+ s.email = ["atapiador@dit.upm.es"]
10
+ s.homepage = ""
11
+ s.summary = %q{A web-scraping API to Google Scholar}
12
+ s.description = %q{A web-scraping API to Google Scholar}
13
+
14
+ s.rubyforge_project = "google_scholar"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+
23
+ s.add_runtime_dependency "nokogiri", "~> 1.5.0"
24
+ s.add_runtime_dependency "activesupport", "> 3.0.0"
25
+ end
@@ -0,0 +1,12 @@
1
+ require "nokogiri"
2
+ require "active_support/memoizable"
3
+
4
+ require "google_scholar/version"
5
+
6
+ module GoogleScholar
7
+ ROOT_URL = 'http://scholar.google.com'
8
+ end
9
+
10
+ require "google_scholar/page"
11
+ require "google_scholar/article"
12
+
@@ -0,0 +1,43 @@
1
+ module GoogleScholar
2
+ class Article
3
+ class << self
4
+ include ActiveSupport::Memoizable
5
+ end
6
+
7
+ attr_reader :doc
8
+
9
+ def initialize(doc)
10
+ @doc = doc
11
+ end
12
+
13
+ def title
14
+ doc.css("h3").text
15
+ end
16
+
17
+ def link
18
+ doc.css('h3 a').first['href']
19
+ end
20
+
21
+ def details
22
+ doc.css('.gs_a').first.text
23
+ end
24
+
25
+ def cites_element
26
+ doc.css('.gs_fl a').select{ |l| l.text =~ /^Cited by/ }.first
27
+ end
28
+
29
+ def cites_link
30
+ cites_element ?
31
+ GoogleScholar::ROOT_URL + cites_element['href'] :
32
+ nil
33
+ end
34
+
35
+ def cites_count
36
+ cites_element ?
37
+ cites_element.text.gsub("Cited by ", "").to_i :
38
+ 0
39
+ end
40
+
41
+ memoize :title, :link, :details, :cites_link, :cites_count
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'open-uri'
2
+
3
+ module GoogleScholar
4
+ class Page
5
+ class << self
6
+ include ActiveSupport::Memoizable
7
+ end
8
+
9
+ attr_reader :url, :doc
10
+
11
+ def initialize(url)
12
+ @url = url
13
+ end
14
+
15
+ def doc
16
+ Nokogiri::HTML(open(url))
17
+ end
18
+
19
+ def articles
20
+ doc.css(".gs_r").map{ |e|
21
+ GoogleScholar::Article.new e
22
+ }
23
+ end
24
+
25
+ memoize :doc, :articles
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module GoogleScholar
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_scholar
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Antonio Tapiador del Dujo
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-23 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 0
48
+ version: 1.5.0
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: activesupport
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">"
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 3
62
+ - 0
63
+ - 0
64
+ version: 3.0.0
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: A web-scraping API to Google Scholar
68
+ email:
69
+ - atapiador@dit.upm.es
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - Rakefile
80
+ - google_scholar.gemspec
81
+ - lib/google_scholar.rb
82
+ - lib/google_scholar/article.rb
83
+ - lib/google_scholar/page.rb
84
+ - lib/google_scholar/version.rb
85
+ has_rdoc: true
86
+ homepage: ""
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirements: []
113
+
114
+ rubyforge_project: google_scholar
115
+ rubygems_version: 1.6.2
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: A web-scraping API to Google Scholar
119
+ test_files: []
120
+