gsearch-parser 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gsearch-parser"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Diego Netto"]
@@ -1,7 +1,63 @@
1
1
  require "gsearch-parser/version"
2
+ require 'open-uri'
3
+ require 'nokogiri'
2
4
 
3
- module Gsearch
4
- module Parser
5
- # Your code goes here...
5
+ module GSearchParser
6
+ def webSearch(query)
7
+ GoogleSearch.new(query)
6
8
  end
7
9
  end
10
+
11
+ ###################################################
12
+ # #
13
+ # GoogleSearch Class #
14
+ # #
15
+ ###################################################
16
+ class GoogleSearch
17
+ attr_accessor :results
18
+
19
+ # Class initializer
20
+ def initialize(query)
21
+ # Initialize array
22
+ @results = Array.new
23
+
24
+ # TODO: Format query
25
+
26
+ # TODO: Fetch page
27
+ searchPage = Nokogiri::HTML(open("http://google.com/search?q=#{query}"))
28
+
29
+ @results << Result.new('title', 'content', "http://www.google.com")
30
+
31
+ # Iterate over all search result divs and parse content into Result objects,
32
+ # and finally store these in the results array
33
+ #searchPage.css('li.g > div.vsc').each do |result|
34
+ # title = result.css('h3.r > a.l').content
35
+ #content = result.css('div.s > span.st').content
36
+ #@results << Result.new('title', 'content', "http://www.google.com")
37
+ #end
38
+ end
39
+
40
+ # Iterator over results
41
+ def each(&blk)
42
+ @results.each(&blk)
43
+ end
44
+
45
+ ###################################################
46
+ # #
47
+ # Result Class #
48
+ # #
49
+ ###################################################
50
+ class Result
51
+ attr_accessor :title, :content, :uri
52
+
53
+ # Class initializer
54
+ def initialize(title, content, uri)
55
+ @title = title
56
+ @content = content
57
+ @uri = uri
58
+ end
59
+
60
+ end # Result
61
+
62
+ end # GoogleSearch
63
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gsearch-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: