google_search_cmdline 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/google_search_cmdline.rb +8 -0
- data/google_search_cmdline.gemspec +71 -0
- data/lib/google_search_cmdline.rb +48 -0
- data/lib/google_search_cmdline_interface.rb +103 -0
- data/lib/google_search_cmdline_result.rb +19 -0
- data/spec/google_search_cmdline_spec.rb +68 -0
- data/spec/spec_helper.rb +12 -0
- metadata +136 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "http2"
|
7
|
+
gem "nokogiri"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.8.0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", ">= 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.8.4"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
http2 (0.0.13)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.7.5)
|
13
|
+
nokogiri (1.5.5)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
rdoc (3.12)
|
16
|
+
json (~> 1.4)
|
17
|
+
rspec (2.8.0)
|
18
|
+
rspec-core (~> 2.8.0)
|
19
|
+
rspec-expectations (~> 2.8.0)
|
20
|
+
rspec-mocks (~> 2.8.0)
|
21
|
+
rspec-core (2.8.0)
|
22
|
+
rspec-expectations (2.8.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.8.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (>= 1.0.0)
|
31
|
+
http2
|
32
|
+
jeweler (~> 1.8.4)
|
33
|
+
nokogiri
|
34
|
+
rdoc (~> 3.12)
|
35
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kasper Johansen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= google_search_cmdline
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to google_search_cmdline
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "google_search_cmdline"
|
18
|
+
gem.homepage = "http://github.com/kaspernj/google_search_cmdline"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A small app for doing Google searches and showing the results on the command line.}
|
21
|
+
gem.description = %Q{A small app for doing Google searches and showing the results on the command line.}
|
22
|
+
gem.email = "k@spernj.org"
|
23
|
+
gem.authors = ["Kasper Johansen"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "google_search_cmdline #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#This file starts the 'Google_search_cmdline'-application.
|
4
|
+
|
5
|
+
require "#{File.realpath(File.dirname(__FILE__))}/../lib/google_search_cmdline.rb"
|
6
|
+
|
7
|
+
gsc = Google_search_cmdline.new
|
8
|
+
interface = Google_search_cmdline::Interface.new(:gsc => gsc)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{google_search_cmdline}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kasper Johansen"]
|
12
|
+
s.date = %q{2012-10-18}
|
13
|
+
s.default_executable = %q{google_search_cmdline.rb}
|
14
|
+
s.description = %q{A small app for doing Google searches and showing the results on the command line.}
|
15
|
+
s.email = %q{k@spernj.org}
|
16
|
+
s.executables = ["google_search_cmdline.rb"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/google_search_cmdline.rb",
|
31
|
+
"google_search_cmdline.gemspec",
|
32
|
+
"lib/google_search_cmdline.rb",
|
33
|
+
"lib/google_search_cmdline_interface.rb",
|
34
|
+
"lib/google_search_cmdline_result.rb",
|
35
|
+
"spec/google_search_cmdline_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/kaspernj/google_search_cmdline}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.6.2}
|
42
|
+
s.summary = %q{A small app for doing Google searches and showing the results on the command line.}
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<http2>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
51
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
56
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
58
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<http2>, [">= 0"])
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "http2" #Used for connecting to the Google-search HTTP-server.
|
3
|
+
require "nokogiri" #Used for parsing HTML.
|
4
|
+
require "cgi" #Used for HTML-escaping.
|
5
|
+
|
6
|
+
#Main class that holds functionality for actually executing the Google-search.
|
7
|
+
#===Examples
|
8
|
+
# gsc = Google_search_cmdline.new
|
9
|
+
# gsc.search("something").each do |result|
|
10
|
+
# #do something with the result
|
11
|
+
# end
|
12
|
+
class Google_search_cmdline
|
13
|
+
#Autoloader for subclasses.
|
14
|
+
def self.const_missing(name)
|
15
|
+
require "#{File.dirname(__FILE__)}/google_search_cmdline_#{name.to_s.downcase}.rb"
|
16
|
+
raise "Still not loaded: '#{name}'." if !Google_search_cmdline.const_defined?(name)
|
17
|
+
return Google_search_cmdline.const_get(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
#This is used to execute a Google-search based on the given text.
|
21
|
+
#===Examples
|
22
|
+
# enum = gsc.search("something")
|
23
|
+
# enum.each do |result|
|
24
|
+
# puts "Title: #{result.title}"
|
25
|
+
# puts "URL: #{result.url}"
|
26
|
+
# end
|
27
|
+
def search(text)
|
28
|
+
return Enumerator.new do |y|
|
29
|
+
Http2.new(:host => "www.google.com", :port => 80) do |http|
|
30
|
+
escaped_str = CGI.escape(text)
|
31
|
+
res = http.get("search?q=#{escaped_str}&oq=#{escaped_str}&sugexp=mod=0&ie=UTF-8")
|
32
|
+
|
33
|
+
doc = Nokogiri.HTML(res.body)
|
34
|
+
doc.css("li.g > h3.r a").each do |a|
|
35
|
+
title = a.content
|
36
|
+
google_url = a.attribute("href").content
|
37
|
+
|
38
|
+
if !match_url = google_url.match(/\/url\?q=(.+?)&sa=U&ei=/)
|
39
|
+
raise "Could not match that Google URL: '#{google_url}'."
|
40
|
+
end
|
41
|
+
|
42
|
+
url = match_url[1]
|
43
|
+
y << Google_search_cmdline::Result.new(:title => title, :url => url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#This class starts a interactive interface based on a 'in'-IO and 'out-IO. If none is given, then 'stdout' and 'stdin' will be used.
|
2
|
+
#===Examples
|
3
|
+
# interface = Google_search_cmdline::Interface.new(:gsc => gsc)
|
4
|
+
class Google_search_cmdline::Interface
|
5
|
+
ALLOWED_ARGUMENTS = [:debug, :gsc, :io_out, :io_in]
|
6
|
+
|
7
|
+
#Constructor.
|
8
|
+
def initialize(args = {})
|
9
|
+
@args = args
|
10
|
+
@args.each do |key, val|
|
11
|
+
raise "Invalid argument: '#{key}'." if !ALLOWED_ARGUMENTS.include?(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
#Used to execute Google-searches.
|
15
|
+
@gsc = @args[:gsc]
|
16
|
+
raise "No ':gsc'-argument was given. This should be a 'Google_search_cmdline' or compatible." if !@gsc
|
17
|
+
|
18
|
+
#Take IO's from arguments or std-IO's.
|
19
|
+
if @args[:io_out]
|
20
|
+
@io_out = @args[:io_out]
|
21
|
+
else
|
22
|
+
@io_out = $stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
if @args[:io_in]
|
26
|
+
@io_in = @args[:io_in]
|
27
|
+
else
|
28
|
+
@io_in = $stdin
|
29
|
+
end
|
30
|
+
|
31
|
+
#If not synced buffers will ruin the application.
|
32
|
+
@io_out.sync = true
|
33
|
+
@io_in.sync = true
|
34
|
+
|
35
|
+
#Commands that should be called directly on the interface-object.
|
36
|
+
direct_cmds = ["exit", "help"]
|
37
|
+
|
38
|
+
@io_out.puts "Welcome to Google Search Cmdline."
|
39
|
+
|
40
|
+
@io_in.each_line do |line_full|
|
41
|
+
begin
|
42
|
+
line = line_full[0, line_full.length - 1]
|
43
|
+
puts "Got line: '#{line}'." if @args[:debug]
|
44
|
+
|
45
|
+
if match = line.match(/^search\s+(.+)$/)
|
46
|
+
@io_out.puts "Searching - please wait..."
|
47
|
+
search_text = match[1]
|
48
|
+
results = @gsc.search(search_text)
|
49
|
+
self.cmd_search(results)
|
50
|
+
elsif direct_cmds.include?(line)
|
51
|
+
self.__send__("cmd_#{line}")
|
52
|
+
elsif line.to_s.strip.empty?
|
53
|
+
#ignore.
|
54
|
+
else
|
55
|
+
@io_out.puts "Can't understand that command: '#{line}'. Try 'help' to see available commands."
|
56
|
+
end
|
57
|
+
rescue => e
|
58
|
+
@io_out.puts "An error occurred: '#{e.message}'."
|
59
|
+
@io_out.puts "Backtrace:"
|
60
|
+
@io_out.puts e.backtrace.join("\n")
|
61
|
+
@io_out.puts ""
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#Called when 'search [something]'. Shows the results of the search.
|
67
|
+
def cmd_search(results)
|
68
|
+
count = 0
|
69
|
+
results.each do |result|
|
70
|
+
count += 1
|
71
|
+
|
72
|
+
@io_out.puts "Result #{count} - #{result.title}"
|
73
|
+
@io_out.puts "URL: #{result.url}"
|
74
|
+
@io_out.puts " "
|
75
|
+
|
76
|
+
if count >= 8
|
77
|
+
@io_out.puts "The maximum of 8 results was found. Please be more specific."
|
78
|
+
break
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if count <= 0
|
83
|
+
@io_out.puts "No results was found (which is very very weird)."
|
84
|
+
end
|
85
|
+
|
86
|
+
@io_out.puts ""
|
87
|
+
end
|
88
|
+
|
89
|
+
#Called when 'exit'.
|
90
|
+
def cmd_exit
|
91
|
+
@io_out.puts "Goodbye."
|
92
|
+
exit
|
93
|
+
end
|
94
|
+
|
95
|
+
#Called when 'help'. Shows a help-message explaining various available commands.
|
96
|
+
def cmd_help
|
97
|
+
@io_out.puts "Available commands:"
|
98
|
+
@io_out.puts " exit - Ends the application."
|
99
|
+
@io_out.puts " help - Shows this message."
|
100
|
+
@io_out.puts " search [text] - Executes a Google search and shots the results."
|
101
|
+
@io_out.puts ""
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#This class represents the results when executing Google_search_cmd#search, which is given by the enumerator.
|
2
|
+
class Google_search_cmdline::Result
|
3
|
+
def initialize(args)
|
4
|
+
@args = args
|
5
|
+
|
6
|
+
raise "Invalid URL: '#{@args[:url]}'." if @args[:url].to_s.strip.empty?
|
7
|
+
raise "Invalid title: '#{@args[:title]}'." if @args[:title].to_s.strip.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
#Returns the title of the result.
|
11
|
+
def title
|
12
|
+
return @args[:title]
|
13
|
+
end
|
14
|
+
|
15
|
+
#Returns the URL of the result.
|
16
|
+
def url
|
17
|
+
return @args[:url]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "GoogleSearchCmdline" do
|
4
|
+
it "should be able to execute Google-searches" do
|
5
|
+
gsc = Google_search_cmdline.new
|
6
|
+
res = gsc.search("kasper").to_a
|
7
|
+
raise "Expected 10 results but got #{res.length}." if res.length != 10
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to start a interface and do handle commands correctly" do
|
11
|
+
#Using TCPSocket's to test the interface.
|
12
|
+
require "socket"
|
13
|
+
|
14
|
+
puts "Starting socket-server, client and connection."
|
15
|
+
tcpserver = TCPServer.new("localhost", 0)
|
16
|
+
tcpclient = TCPSocket.new("localhost", tcpserver.addr[1])
|
17
|
+
tcpserverc = tcpserver.accept
|
18
|
+
|
19
|
+
puts "Spawning 'Google_search_cmdline'."
|
20
|
+
gsc = Google_search_cmdline.new
|
21
|
+
|
22
|
+
puts "Starting interface."
|
23
|
+
Thread.new do
|
24
|
+
begin
|
25
|
+
interface = Google_search_cmdline::Interface.new(:debug => true, :gsc => gsc, :io_out => tcpserverc, :io_in => tcpserverc)
|
26
|
+
rescue SystemExit
|
27
|
+
#ignore - called at the end of the test.
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "Waiting for welcome-message."
|
32
|
+
line_welcome = tcpclient.gets
|
33
|
+
raise "Expected welcome-line but got: '#{line_welcome}'." if line_welcome != "Welcome to Google Search Cmdline.\n"
|
34
|
+
|
35
|
+
puts "Sending command."
|
36
|
+
tcpclient.puts "help"
|
37
|
+
|
38
|
+
puts "Getting first line."
|
39
|
+
line_acmds = tcpclient.gets
|
40
|
+
|
41
|
+
puts "Testing."
|
42
|
+
raise "Expected 'Available commands' but got: '#{line_acmds}'." if line_acmds != "Available commands:\n"
|
43
|
+
|
44
|
+
#Read the rest of the help-message.
|
45
|
+
tcpclient.each_line do |line|
|
46
|
+
break if line == "\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
result_no = nil
|
50
|
+
|
51
|
+
tcpclient.puts "search kasper"
|
52
|
+
tcpclient.each_line do |line|
|
53
|
+
puts "Search: #{line}"
|
54
|
+
|
55
|
+
if match = line.match(/^Result (\d+) -/)
|
56
|
+
result_no = match[1].to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
break if line == "\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
raise "Expected 8 results but got '#{result_no}'." if result_no != 8
|
63
|
+
|
64
|
+
tcpclient.puts "exit"
|
65
|
+
line_goodbye = tcpclient.gets
|
66
|
+
raise "Expected goodbye-message but got: '#{line_goodbye}'." if line_goodbye != "Goodbye.\n"
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'google_search_cmdline'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_search_cmdline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kasper Johansen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-18 00:00:00.000000000 +02:00
|
13
|
+
default_executable: google_search_cmdline.rb
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: http2
|
17
|
+
requirement: &18962180 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *18962180
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: nokogiri
|
28
|
+
requirement: &18961000 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *18961000
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &18959200 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.8.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *18959200
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rdoc
|
50
|
+
requirement: &18958280 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.12'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *18958280
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &18956740 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *18956740
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &18955520 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *18955520
|
81
|
+
description: A small app for doing Google searches and showing the results on the
|
82
|
+
command line.
|
83
|
+
email: k@spernj.org
|
84
|
+
executables:
|
85
|
+
- google_search_cmdline.rb
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- bin/google_search_cmdline.rb
|
100
|
+
- google_search_cmdline.gemspec
|
101
|
+
- lib/google_search_cmdline.rb
|
102
|
+
- lib/google_search_cmdline_interface.rb
|
103
|
+
- lib/google_search_cmdline_result.rb
|
104
|
+
- spec/google_search_cmdline_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/kaspernj/google_search_cmdline
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
hash: 4058528874569921273
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.6.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: A small app for doing Google searches and showing the results on the command
|
135
|
+
line.
|
136
|
+
test_files: []
|