Class: RubyWebshot

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

Class Method Summary collapse

Class Method Details

.call(url_to_shot, args = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_webshot.rb', line 5

def self.call(url_to_shot, args = {}) 
    return nil if url_to_shot.nil?
    
    initialize

    #get the parameters or set default
    options = args

    file_name = options[:file_name] || "#{Time.now.strftime("%d-%m-%Y-%H%M%S")}.png"
    p file_name
    save_file_path = options[:save_file_path] ? "#{options[:save_file_path]}/#{file_name}" : "#{Dir.pwd}/#{file_name}"

    p save_file_path

    width = options[:width] || 860
    height = options[:height] || 860

    #navigate to a url to shot
    @driver.navigate.to url_to_shot

    #resize shot and save
    @driver.manage.window.resize_to(width, height)
    @driver.save_screenshot save_file_path

    #finish
    finalize
end