Class: Mnemosyne::WebPageSnapshot
- Inherits:
-
Object
- Object
- Mnemosyne::WebPageSnapshot
- Defined in:
- lib/mnemosyne/web_page_snapshot.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(dir = "screenshots/") ⇒ WebPageSnapshot
constructor
A new instance of WebPageSnapshot.
- #take_snapshot(domain) ⇒ Object
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
#close ⇒ Object
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 |