screenshot 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de0d3273a0f51eb030ed4ffbc1246b9a27b8d54a
4
- data.tar.gz: dc957f799ef90603363030868155b71db5859067
3
+ metadata.gz: 6bb9409814f8b73227b3a3660ef7671e5f78f06f
4
+ data.tar.gz: f7cc631935cb2d503bce99e7e60741735b3c5667
5
5
  SHA512:
6
- metadata.gz: c64ff46d750fca6f1741a38aa36ebb0c13a2563ee9b2ecee28349520f1fecfb7274d8edf30236585837621ddb2c1f0fbbc47d57d000fae79375ff90fdfdb50a1
7
- data.tar.gz: b44c80ab8b3526e013dd502008b3680246be5dc15fc5b9a1367ebde8aae167b2683db8cd555d5b77c29077beb273d7d6cb2c45f50860c6048bc75282a8ec5eb6
6
+ metadata.gz: afb6aca9737cfa6b69c2ef357c1a64807b98180ef4cbb4fbeb35a797ecc1a4d12bc5347f2ee89db06f1e64b6749e3086d66595c0cf831a2581e6faed9f7fcfca
7
+ data.tar.gz: 1b48c5ed90b1baacfa4fbf7233fa858ae5303beca5ae2c73c2a88c8f91605b7ed489cfbff9e5a0017655c921d8188f9933d164ce30607c4250f917395180f7d5
@@ -1 +1,9 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ # The default is 15, which is too tight
4
+ Metrics/AbcSize:
5
+ Max: 30
6
+
7
+ # The default is 10, which is too tight
8
+ Metrics/MethodLength:
9
+ Max: 20
@@ -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:
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ install: bundle install
5
+ script:
6
+ - bundle exec rspec
7
+ - bundle exec rubocop
@@ -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, nil
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, offset_element)
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, offset_rectangle)
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, offset_rectangle = [0, 0, 0, 0])
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 + x_offset, top_left_y + y_offset, width, height]
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)
@@ -1,3 +1,3 @@
1
1
  module Screenshot
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -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.5
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-02-17 00:00:00.000000000 Z
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