Class: Mnemosyne::WebPageSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/mnemosyne/web_page_snapshot.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir = "screenshots/") ⇒ WebPageSnapshot

Returns a new instance of WebPageSnapshot.



5
6
7
8
# File 'lib/mnemosyne/web_page_snapshot.rb', line 5

def initialize(dir = "screenshots/")
    @directory = dir
    @browser = Watir::Browser.new :firefox, headless: true
end

Instance Method Details

#closeObject



24
25
26
# File 'lib/mnemosyne/web_page_snapshot.rb', line 24

def close
    @browser.close
end

#take_snapshot(domain) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mnemosyne/web_page_snapshot.rb', line 10

def take_snapshot(domain)
    begin
        @browser.goto "https://#{domain}"
    rescue => e
        @browser.goto "http://#{domain}"
    end
    ensure_directory_exists
    filename = "#{sanitized_domain(domain)}.png"
    @browser.screenshot.save("#{@directory}#{filename}")
    filename
rescue => e
    nil
end