Class: GoogleBrowse::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/google_browse/browser.rb

Constant Summary collapse

DEFAULT_RESULTS_PER_PAGE =
5
MIN_RESULTS_PER_PAGE =
1
MAX_RESULTS_PER_PAGE =

Avoid being rude to Google.

20
NUM_COLUMNS =
79

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Browser

Returns a new instance of Browser.

Parameters:

  • :results_per_page (Hash)

    a customizable set of options

  • :query (Hash)

    a customizable set of options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/google_browse/browser.rb', line 19

def initialize(options = {})
  options = {
    results_per_page: DEFAULT_RESULTS_PER_PAGE,
  }.merge! options

  @results_per_page = [
      [MIN_RESULTS_PER_PAGE, options[:results_per_page]].max,
      MAX_RESULTS_PER_PAGE
  ].min

  @quit = false

  if options[:query]
    @scraper = Scraper.new options[:query]
  else
    @scraper = nil
    input_new_search
  end

  @page_number = 0

  puts
  list_links
  navigate until quit?
end

Class Method Details

.search(*args) ⇒ Object



14
# File 'lib/google_browse/browser.rb', line 14

def search(*args); new *args; end