Class: Rack::SearchTerms
- Inherits:
-
Object
- Object
- Rack::SearchTerms
- Includes:
- Utils
- Defined in:
- lib/rack-search_terms.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ SearchTerms
constructor
A new instance of SearchTerms.
- #referer ⇒ Object
- #search_terms ⇒ Object
- #terms_from_param(param) ⇒ Object
Constructor Details
#initialize(app) ⇒ SearchTerms
Returns a new instance of SearchTerms.
7 8 9 |
# File 'lib/rack-search_terms.rb', line 7 def initialize app @app = app end |
Class Method Details
.version ⇒ Object
37 |
# File 'lib/rack-search_terms.rb', line 37 def self.version; '0.1.0'; end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 |
# File 'lib/rack-search_terms.rb', line 11 def call env @env = env @env.merge! 'search_terms' => search_terms @app.call @env end |
#referer ⇒ Object
17 18 19 |
# File 'lib/rack-search_terms.rb', line 17 def referer @env['HTTP_REFERER'] end |
#search_terms ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rack-search_terms.rb', line 21 def search_terms case referer when /^http:\/\/www\.google\..*?\/imgres/ prev = terms_from_param 'prev' parse_query(prev.split('?')[1])['q'] when /^http:\/\/www\.google\..*?\// terms_from_param 'q' when /^http:\/\/www.bing.com/ terms_from_param 'q' end end |
#terms_from_param(param) ⇒ Object
33 34 35 |
# File 'lib/rack-search_terms.rb', line 33 def terms_from_param param parse_query(URI.parse(referer).query)[param] end |