screenshot 0.0.5 → 0.0.6
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 +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +0 -15
- data/.travis.yml +7 -0
- data/lib/screenshot.rb +6 -15
- data/lib/screenshot/version.rb +1 -1
- data/spec/rectangle_spec.rb +10 -8
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bb9409814f8b73227b3a3660ef7671e5f78f06f
|
|
4
|
+
data.tar.gz: f7cc631935cb2d503bce99e7e60741735b3c5667
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: afb6aca9737cfa6b69c2ef357c1a64807b98180ef4cbb4fbeb35a797ecc1a4d12bc5347f2ee89db06f1e64b6749e3086d66595c0cf831a2581e6faed9f7fcfca
|
|
7
|
+
data.tar.gz: 1b48c5ed90b1baacfa4fbf7233fa858ae5303beca5ae2c73c2a88c8f91605b7ed489cfbff9e5a0017655c921d8188f9933d164ce30607c4250f917395180f7d5
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
|
@@ -5,20 +5,11 @@
|
|
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
|
7
7
|
|
|
8
|
-
# Offense count: 2
|
|
9
|
-
Metrics/AbcSize:
|
|
10
|
-
Max: 19
|
|
11
|
-
|
|
12
8
|
# Offense count: 53
|
|
13
9
|
# Configuration parameters: AllowURI, URISchemes.
|
|
14
10
|
Metrics/LineLength:
|
|
15
11
|
Max: 288
|
|
16
12
|
|
|
17
|
-
# Offense count: 1
|
|
18
|
-
# Configuration parameters: CountComments.
|
|
19
|
-
Metrics/MethodLength:
|
|
20
|
-
Max: 16
|
|
21
|
-
|
|
22
13
|
# Offense count: 2
|
|
23
14
|
Style/Documentation:
|
|
24
15
|
Enabled: false
|
|
@@ -43,12 +34,6 @@ Style/RegexpLiteral:
|
|
|
43
34
|
Style/SpecialGlobalVars:
|
|
44
35
|
Enabled: false
|
|
45
36
|
|
|
46
|
-
# Offense count: 1
|
|
47
|
-
# Cop supports --auto-correct.
|
|
48
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
49
|
-
Style/StringLiterals:
|
|
50
|
-
Enabled: false
|
|
51
|
-
|
|
52
37
|
# Offense count: 2
|
|
53
38
|
# Cop supports --auto-correct.
|
|
54
39
|
Style/UnneededPercentQ:
|
data/.travis.yml
ADDED
data/lib/screenshot.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
require 'screenshot/version'
|
|
2
2
|
|
|
3
3
|
module Screenshot
|
|
4
|
-
def self.capture(browser, file_name, page_elements)
|
|
4
|
+
def self.capture(browser, file_name, page_elements, padding = 0)
|
|
5
5
|
screenshot_directory = ENV['LANGUAGE_SCREENSHOT_PATH'] || 'screenshots'
|
|
6
6
|
FileUtils.mkdir_p screenshot_directory
|
|
7
7
|
screenshot_path = "#{screenshot_directory}/#{file_name}"
|
|
8
8
|
|
|
9
9
|
browser.screenshot.save screenshot_path
|
|
10
|
-
self.crop_image screenshot_path, page_elements,
|
|
10
|
+
self.crop_image screenshot_path, page_elements, padding
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def self.zoom_browser(browser, rate)
|
|
@@ -17,14 +17,9 @@ module Screenshot
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def self.crop_image(path, page_elements,
|
|
21
|
-
if offset_element
|
|
22
|
-
offset_rectangle = coordinates_from_page_element(offset_element)
|
|
23
|
-
else
|
|
24
|
-
offset_rectangle = [0, 0, 0, 0]
|
|
25
|
-
end
|
|
20
|
+
def self.crop_image(path, page_elements, padding)
|
|
26
21
|
rectangles = self.coordinates_from_page_elements(page_elements)
|
|
27
|
-
crop_rectangle = rectangle(rectangles,
|
|
22
|
+
crop_rectangle = rectangle(rectangles, padding)
|
|
28
23
|
|
|
29
24
|
top_left_x = crop_rectangle[0]
|
|
30
25
|
top_left_y = crop_rectangle[1]
|
|
@@ -42,7 +37,7 @@ module Screenshot
|
|
|
42
37
|
image.save path
|
|
43
38
|
end
|
|
44
39
|
|
|
45
|
-
def self.rectangle(rectangles,
|
|
40
|
+
def self.rectangle(rectangles, padding = 0)
|
|
46
41
|
top_left_x, top_left_y = top_left_x_y rectangles
|
|
47
42
|
bottom_right_x, bottom_right_y = bottom_right_x_y rectangles
|
|
48
43
|
|
|
@@ -50,12 +45,8 @@ module Screenshot
|
|
|
50
45
|
width = bottom_right_x - top_left_x
|
|
51
46
|
height = bottom_right_y - top_left_y
|
|
52
47
|
|
|
53
|
-
# We are calculating the offset co-ordinates
|
|
54
|
-
x_offset = offset_rectangle[0]
|
|
55
|
-
y_offset = offset_rectangle[1]
|
|
56
|
-
|
|
57
48
|
# The new rectangle is constructed with all the co-ordinates calculated above
|
|
58
|
-
[top_left_x
|
|
49
|
+
[top_left_x - padding, top_left_y - padding, width + padding * 2, height + padding * 2]
|
|
59
50
|
end
|
|
60
51
|
|
|
61
52
|
def self.coordinates_from_page_elements(page_elements)
|
data/lib/screenshot/version.rb
CHANGED
data/spec/rectangle_spec.rb
CHANGED
|
@@ -8,14 +8,6 @@ describe 'Rectangle' do
|
|
|
8
8
|
expect(Screenshot.rectangle(input_rectangles)).to eq(input_rectangle)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it 'should return the co-ordinates of the rectangle which is inside a iframe' do
|
|
12
|
-
input_rectangle = [50, 50, 10, 10]
|
|
13
|
-
iframe_rectangle = [100, 100, 20, 20]
|
|
14
|
-
input_rectangles = [input_rectangle]
|
|
15
|
-
output_rectangle = [150, 150, 10, 10]
|
|
16
|
-
expect(Screenshot.rectangle(input_rectangles, iframe_rectangle)).to eq(output_rectangle)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
11
|
it 'if we provide 2 rectangles and if one contains the other then it should return co-ordinates of bigger rectangle' do
|
|
20
12
|
input_rectangle_1 = [0, 0, 1, 1]
|
|
21
13
|
input_rectangle_2 = [0, 0, 2, 2]
|
|
@@ -202,3 +194,13 @@ describe 'Bottom right co-ordinates y' do
|
|
|
202
194
|
expect(Screenshot.bottom_right_y_coordinates(input_rectangles)).to eq(output_coordinates)
|
|
203
195
|
end
|
|
204
196
|
end
|
|
197
|
+
|
|
198
|
+
describe 'Bottom right co-ordinates y' do
|
|
199
|
+
it 'if we provide 1 rectangle and a padding of 2 pixels, the rectangle is increased by 2 pixels on each side' do
|
|
200
|
+
input_rectangle = [7, 42, 19, 125]
|
|
201
|
+
output_rectangle = [5, 40, 23, 129]
|
|
202
|
+
padding = 2
|
|
203
|
+
input_rectangles = [input_rectangle]
|
|
204
|
+
expect(Screenshot.rectangle(input_rectangles, padding)).to eq(output_rectangle)
|
|
205
|
+
end
|
|
206
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: screenshot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vikas Yaligar
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2015-
|
|
13
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: chunky_png
|
|
@@ -95,6 +95,7 @@ files:
|
|
|
95
95
|
- .gitignore
|
|
96
96
|
- .rubocop.yml
|
|
97
97
|
- .rubocop_todo.yml
|
|
98
|
+
- .travis.yml
|
|
98
99
|
- Gemfile
|
|
99
100
|
- LICENSE.txt
|
|
100
101
|
- README.md
|