Class: GoogleAjaxCrawler::Drivers::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/google_ajax_crawler/drivers/driver.rb

Direct Known Subclasses

CapybaraWebkit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Driver

Returns a new instance of Driver.



7
8
9
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 7

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 5

def options
  @options
end

Instance Method Details

#default_page_loaded_testObject



19
20
21
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 19

def default_page_loaded_test
  raise "Driver Not Specified"
end

#evaluate_script(javascript) ⇒ Object



15
16
17
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 15

def evaluate_script(javascript)
  raise "Driver Not Specified"
end

#get_content(uri) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 27

def get_content(uri)
  begin
    puts "::requesting: #{uri}"
    visit uri.to_s
    wait_until_page_is_fully_loaded
  rescue Timeout::Error
    puts  "-- Page Rendering Timed out: --\n"\
          "Either your page_loaded_test didn't successfully detect when your page had loaded, \n"\
          "or your page took longer than #{options.timeout} seconds to load \n"\
          "-- Returning page snapshot in its present state --"
  end
  html
end

#htmlObject



23
24
25
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 23

def html
  raise "Driver Not Specified"
end

#is_page_loaded?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 41

def is_page_loaded?
  return evaluate_script(options.page_loaded_js) unless options.page_loaded_js.nil?
  return options.page_loaded_test.call(self) unless options.page_loaded_test.nil?
  default_page_loaded_test
end

#visit(url) ⇒ Object



11
12
13
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 11

def visit(url)
  raise "Driver Not Specified"
end

#wait_until_page_is_fully_loadedObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/google_ajax_crawler/drivers/driver.rb', line 47

def wait_until_page_is_fully_loaded
  Timeout::timeout(options.timeout) do
    begin
      sleep(options.poll_interval) while !is_page_loaded?
    rescue
      #...squelch
      puts "Exception: #{$!}"
    end
  end
end