ruby_webshot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/ruby_webshot.rb +47 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '090004fc20b38b0c93f19dd49eb48b1217d94839997f2457d188e2e2c9f66c94'
|
|
4
|
+
data.tar.gz: 14334be8fdfeb1d005a2eb354d245475ab49fd5240d0a4c86349ca6c61384d72
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c89ca0fdb97b5da7075c75c5cde383ff15ac8d0d434befe1a8dfc4a6db1ea7da44b678ea438f524b9333ebd8b1919d3d687685edccf0efe0648e1f0ca0454c42
|
|
7
|
+
data.tar.gz: 8f9e94566718896b630dab8e4fd1f624af6627c280766f22f9ef868bce9bca379c4145c3ed87a188bf72146895cb594108ef2583f82a667459b5c84bf7ffd253
|
data/lib/ruby_webshot.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'webdrivers'
|
|
2
|
+
|
|
3
|
+
class RubyWebshot
|
|
4
|
+
|
|
5
|
+
def self.call(url_to_shot, args = {})
|
|
6
|
+
return nil if url_to_shot.nil?
|
|
7
|
+
|
|
8
|
+
initialize
|
|
9
|
+
|
|
10
|
+
#get the parameters or set default
|
|
11
|
+
options = args
|
|
12
|
+
|
|
13
|
+
file_name = options[:file_name] || "#{Time.now.strftime("%d-%m-%Y-%H%M%S")}.png"
|
|
14
|
+
p file_name
|
|
15
|
+
save_file_path = options[:save_file_path] ? "#{options[:save_file_path]}/#{file_name}" : "#{Dir.pwd}/#{file_name}"
|
|
16
|
+
|
|
17
|
+
p save_file_path
|
|
18
|
+
|
|
19
|
+
width = options[:width] || 860
|
|
20
|
+
height = options[:height] || 860
|
|
21
|
+
|
|
22
|
+
#navigate to a url to shot
|
|
23
|
+
@driver.navigate.to url_to_shot
|
|
24
|
+
|
|
25
|
+
#resize shot and save
|
|
26
|
+
@driver.manage.window.resize_to(width, height)
|
|
27
|
+
@driver.save_screenshot save_file_path
|
|
28
|
+
|
|
29
|
+
#finish
|
|
30
|
+
finalize
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def self.initialize
|
|
36
|
+
# setting the driver for a headless mode
|
|
37
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
|
38
|
+
options.add_argument('--headless')
|
|
39
|
+
options.add_argument('--hide-scrollbars')
|
|
40
|
+
@driver = Selenium::WebDriver.for :chrome, options: options
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.finalize
|
|
44
|
+
@driver.quit
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby_webshot
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nezir Z.
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-12-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Ruby Webshot gem will make nice webshots for you
|
|
14
|
+
email: nezir.zahirovic at gmail com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/ruby_webshot.rb
|
|
20
|
+
homepage: https://rubygems.org/gems/ruby_webshot
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.0.3
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Ruby Webshot
|
|
43
|
+
test_files: []
|