Class: Gastly::Screenshot
- Inherits:
-
Object
- Object
- Gastly::Screenshot
- Defined in:
- lib/gastly/screenshot.rb
Constant Summary collapse
- SCRIPT_PATH =
File.('../script.js', __FILE__)
- DEFAULT_TIMEOUT =
0
- DEFAULT_BROWSER_WIDTH =
1440
- DEFAULT_BROWSER_HEIGHT =
900
- DEFAULT_FILE_FORMAT =
'.png'.freeze
Instance Attribute Summary collapse
-
#browser_height ⇒ Object
writeonly
Sets the attribute browser_height.
-
#browser_width ⇒ Object
writeonly
Sets the attribute browser_width.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#phantomjs_options ⇒ Object
Returns the value of attribute phantomjs_options.
-
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#selector ⇒ Object
Returns the value of attribute selector.
-
#timeout ⇒ Object
writeonly
Sets the attribute timeout.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#capture ⇒ Gastly::Image
Capture image via PhantomJS and save to output file.
-
#initialize(url, **kwargs) ⇒ Screenshot
constructor
A new instance of Screenshot.
Constructor Details
#initialize(url, **kwargs) ⇒ Screenshot
Returns a new instance of Screenshot.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gastly/screenshot.rb', line 14 def initialize(url, **kwargs) hash = Gastly::Utils::Hash.new(kwargs) hash.assert_valid_keys(:timeout, :browser_width, :browser_height, :selector, :cookies, :proxy_host, :proxy_port, :phantomjs_options) @url = url @cookies = kwargs.delete(:cookies) @image = MiniMagick::Image.create(DEFAULT_FILE_FORMAT, false) # Disable validation kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) } end |
Instance Attribute Details
#browser_height=(value) ⇒ Object (writeonly)
Sets the attribute browser_height
10 11 12 |
# File 'lib/gastly/screenshot.rb', line 10 def browser_height=(value) @browser_height = value end |
#browser_width=(value) ⇒ Object (writeonly)
Sets the attribute browser_width
10 11 12 |
# File 'lib/gastly/screenshot.rb', line 10 def browser_width=(value) @browser_width = value end |
#cookies ⇒ Object
Returns the value of attribute cookies.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def @cookies end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
9 10 11 |
# File 'lib/gastly/screenshot.rb', line 9 def image @image end |
#phantomjs_options ⇒ Object
Returns the value of attribute phantomjs_options.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def @phantomjs_options end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def proxy_host @proxy_host end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def proxy_port @proxy_port end |
#selector ⇒ Object
Returns the value of attribute selector.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def selector @selector end |
#timeout=(value) ⇒ Object (writeonly)
Sets the attribute timeout
10 11 12 |
# File 'lib/gastly/screenshot.rb', line 10 def timeout=(value) @timeout = value end |
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/gastly/screenshot.rb', line 11 def url @url end |
Instance Method Details
#capture ⇒ Gastly::Image
Capture image via PhantomJS and save to output file
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gastly/screenshot.rb', line 29 def capture # This necessary to install PhantomJS via proxy Phantomjs.proxy_host = proxy_host if proxy_host Phantomjs.proxy_port = proxy_port if proxy_port output = Phantomjs.run(, SCRIPT_PATH.to_s, *prepared_params) handle_output(output) Gastly::Image.new(image) end |