search_terms 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format=doc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in search_terms.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # search\_terms
2
+
3
+ **TL;DR**: **search\_terms** extracts search terms (keywords) from
4
+ search engine referral URLs
5
+
6
+ ## Quick Examples
7
+
8
+ ```ruby
9
+ require "rubygems"
10
+ require "search_terms"
11
+
12
+ referrer = URI("http://google.com/?q=how+to+extract+search+terms")
13
+ referrer.search_string # => "how to extract search terms"
14
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ require "uri"
2
+ require "cgi"
3
+
4
+ require "search_terms/version"
5
+ require "search_terms/extractor"
6
+
7
+ require "search_terms/ext/uri"
@@ -0,0 +1,3 @@
1
+ class URI::Generic
2
+ include SearchTerms::Extractor
3
+ end
@@ -0,0 +1,37 @@
1
+ module SearchTerms
2
+ # Expects to be mixed into an object that responds to:
3
+ # * fragment: URI parameters after a #
4
+ # * query: URI parameters afer a ?
5
+ # * host: URI host
6
+ module Extractor
7
+ def search_string
8
+ case search_engine
9
+ when :google, :bing, :aol, :duckduckgo
10
+ query_parameters["q"].first
11
+ when :yahoo
12
+ query_parameters["p"].first
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def search_engine
19
+ case host
20
+ when /google\./
21
+ :google
22
+ when /bing\./
23
+ :bing
24
+ when /yahoo\./
25
+ :yahoo
26
+ when /search\.aol\./
27
+ :aol
28
+ when /duckduckgo\./
29
+ :duckduckgo
30
+ end
31
+ end
32
+
33
+ def query_parameters
34
+ CGI.parse(query || fragment || "")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module SearchTerms
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "search_terms/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "search_terms"
7
+ s.version = SearchTerms::VERSION
8
+ s.authors = ["Andy Lindeman"]
9
+ s.email = ["alindeman@gmail.com"]
10
+ s.homepage = "https://github.com/alindeman/search_terms"
11
+ s.summary = %q{Extracts search terms from search engine referral URLs}
12
+ s.description = %q{Supports extracting search terms from Google, Bing, Yahoo, DuckDuckGo, and AOL}
13
+
14
+ s.rubyforge_project = "search_terms"
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", "~>2.7.0"
22
+ s.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe SearchTerms::Extractor do
4
+ context "non-search engine" do
5
+ it "returns nil for search terms even if they are present" do
6
+ uri = URI("http://andylindeman.com/?q=how+to+do+everything")
7
+ uri.search_string.should be_nil
8
+ end
9
+
10
+ it "returns nil for search terms if they are not present" do
11
+ uri = URI("http://andylindeman.com/")
12
+ uri.search_string.should be_nil
13
+ end
14
+ end
15
+
16
+ context "google" do
17
+ it "returns search terms from query string" do
18
+ uri = URI("http://google.com/?q=how+to+extract+search+terms")
19
+ uri.search_string.should == "how to extract search terms"
20
+ end
21
+
22
+ it "returns search terms from query fragment" do
23
+ uri = URI("http://google.com/#q=how+to+extract+search+terms")
24
+ uri.search_string.should == "how to extract search terms"
25
+ end
26
+ end
27
+
28
+ context "yahoo" do
29
+ it "returns search terms from query string" do
30
+ uri = URI("http://search.yahoo.com/search;_ylt=abc123?p=how+to+extract+search+terms")
31
+ uri.search_string.should == "how to extract search terms"
32
+ end
33
+ end
34
+
35
+ context "bing" do
36
+ it "returns search terms from query string" do
37
+ uri = URI("http://www.bing.com/search?q=how+to+extract+search+terms")
38
+ uri.search_string.should == "how to extract search terms"
39
+ end
40
+ end
41
+
42
+ context "aol" do
43
+ it "returns search terms from query string" do
44
+ uri = URI("http://search.aol.com/aol/search?q=how+to+extract+search+terms")
45
+ uri.search_string.should == "how to extract search terms"
46
+ end
47
+ end
48
+
49
+ context "duckduckgo" do
50
+ it "returns search terms from query string" do
51
+ uri = URI("http://duckduckgo.com/?q=how+to+extract+search+terms")
52
+ uri.search_string.should == "how to extract search terms"
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.require(:default, :development)
4
+
5
+ require File.expand_path("../lib/search_terms", File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: search_terms
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
+ - Andy Lindeman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 19
27
+ segments:
28
+ - 2
29
+ - 7
30
+ - 0
31
+ version: 2.7.0
32
+ requirement: *id001
33
+ type: :development
34
+ prerelease: false
35
+ name: rspec
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ type: :development
48
+ prerelease: false
49
+ name: rake
50
+ description: Supports extracting search terms from Google, Bing, Yahoo, DuckDuckGo, and AOL
51
+ email:
52
+ - alindeman@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - .gitignore
61
+ - .rspec
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/search_terms.rb
66
+ - lib/search_terms/ext/uri.rb
67
+ - lib/search_terms/extractor.rb
68
+ - lib/search_terms/version.rb
69
+ - search_terms.gemspec
70
+ - spec/search_terms_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/alindeman/search_terms
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: search_terms
101
+ rubygems_version: 1.8.10
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Extracts search terms from search engine referral URLs
105
+ test_files:
106
+ - spec/search_terms_spec.rb
107
+ - spec/spec_helper.rb