flash_flow 1.5.1 → 1.5.2

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: bcac5f48c7e0f0cf6700988e91ac9dbaa949050b
4
- data.tar.gz: d51fa3318c6841aefcbc0ef09787c4758e575bab
3
+ metadata.gz: 8e906c19c6979dd04796aa3a4a120c43708b8b31
4
+ data.tar.gz: a711a9219a03243b4cae5b79f5bf9fb000593995
5
5
  SHA512:
6
- metadata.gz: f415a2e12db0081979a922a26b319e42762bd5dad73e2bb383281234250c1001f0d73858b731caa85cf884b5617598a3708bd78e975ba9442ad33d1342d6714b
7
- data.tar.gz: 749e4d8213f85e8a37ac3bbf35369b6ef2dc4579ed231cc47f19120670411952e8c3a180be2ab3f41fea30c441464d047b247180a2de00059f4648003a9113f5
6
+ metadata.gz: d93ca428a41c0af6328589732b5623eec00327e4fca74d943f247ba27089786a83006f90478ad4d49db59290af34b13bae5c6b0b28beb2a7c58fe00c8c159daf
7
+ data.tar.gz: 55777d04af267fb1dfd287285ade1f268876386838c6a0e077983eeedd92793961f5c5c67a72749fb820110ece023d62b08d30de77dbb8644a87e5ce15d2948c
@@ -47,15 +47,15 @@ module FlashFlow
47
47
  pdf.text("Compliance Diffs Generated At: #{Time.now.to_s}")
48
48
  end
49
49
 
50
- def compute_scale_factor(column_width, page_height, info)
51
- x_scale_factor = column_width / info[:width]
52
- y_scale_factor = page_height / info[:height]
50
+ def compute_scale_factor(column_width, page_height, width, height)
51
+ x_scale_factor = column_width / width
52
+ y_scale_factor = page_height / height
53
53
  [x_scale_factor, y_scale_factor].min
54
54
  end
55
55
 
56
- def compute_scale_and_orientation(info)
57
- scale_portrait = compute_scale_factor(@column_portrait, [@page_width, @page_height].max, info)
58
- scale_landscape = compute_scale_factor(@column_landscape, [@page_width, @page_height].min, info)
56
+ def compute_scale_and_orientation(width, height)
57
+ scale_portrait = compute_scale_factor(@column_portrait, [@page_width, @page_height].max, width, height)
58
+ scale_landscape = compute_scale_factor(@column_landscape, [@page_width, @page_height].min, width, height)
59
59
  if scale_portrait > scale_landscape
60
60
  @orientation = :portrait
61
61
  @column_width = @column_portrait
@@ -67,14 +67,25 @@ module FlashFlow
67
67
  end
68
68
  end
69
69
 
70
+ def max_width(comparison)
71
+ max_by(comparison, :width)
72
+ end
73
+
74
+ def max_height(comparison)
75
+ max_by(comparison, :height)
76
+ end
77
+
78
+ def max_by(comparison, key)
79
+ [comparison['head-screenshot'][key], comparison['base-screenshot'][key], comparison['pdiff'][key]].max
80
+ end
81
+
70
82
  def add_comparison_to_pdf(pdf, comparison)
71
- scale_factor = compute_scale_and_orientation(comparison['head-screenshot'])
83
+ scale_factor = compute_scale_and_orientation(max_width(comparison), max_height(comparison))
72
84
  options = { vposition: :top, scale: scale_factor }
73
85
 
74
86
  pdf.start_new_page(layout: @orientation)
75
-
76
- place_image(pdf, comparison.dig('head-screenshot', :url), options, 1)
77
- place_image(pdf, comparison.dig('base-screenshot', :url), options, 2)
87
+ place_image(pdf, comparison.dig('base-screenshot', :url), options, 1)
88
+ place_image(pdf, comparison.dig('head-screenshot', :url), options, 2)
78
89
  place_image(pdf, comparison.dig('base-screenshot', :url), options, 3)
79
90
  place_image(pdf, comparison.dig('pdiff', :url), options, 3)
80
91
  end
@@ -82,10 +93,15 @@ module FlashFlow
82
93
  def place_image(pdf, url, options, column)
83
94
  pdf.float do
84
95
  options[:position] = (column - 1) * (@column_width + SPACE_BETWEEN)
85
- pdf.image(open(url), options)
96
+ pdf.image(get_url_once(url), options)
86
97
  end
87
98
  end
88
99
 
100
+ def get_url_once(url)
101
+ @already_gotten_urls ||= {}
102
+ @already_gotten_urls[url] ||= open(url)
103
+ end
104
+
89
105
  ####################################
90
106
  # #
91
107
  # Methods to traverse Percy output #
@@ -93,14 +109,11 @@ module FlashFlow
93
109
  ####################################
94
110
 
95
111
  def collect_comparison_info(compare_info, threshold=0.0)
96
- [].tap do |result|
97
- compare_info['data'].each do |record|
98
- if record['type'] == 'comparisons'
99
- comparison_urls = get_comparison_info(record, compare_info)
100
- result << comparison_urls if comparison_urls&.dig('diff-ratio').to_f > threshold
101
- end
102
- end
103
- end
112
+ compare_info['data']
113
+ .select { |record| record['type'] == 'comparisons' }
114
+ .map { |record| get_comparison_info(record, compare_info) }
115
+ .select { |record| record&.dig('diff-ratio').to_f > threshold }
116
+ .sort { |a, b| b['diff-ratio'] <=> a['diff-ratio'] }
104
117
  end
105
118
 
106
119
  def get_comparison_info(record, data)
@@ -1,3 +1,3 @@
1
1
  module FlashFlow
2
- VERSION = '1.5.1'
2
+ VERSION = '1.5.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flash_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flashfunders
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-24 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -298,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  requirements: []
300
300
  rubyforge_project:
301
- rubygems_version: 2.5.1
301
+ rubygems_version: 2.6.9
302
302
  signing_key:
303
303
  specification_version: 4
304
304
  summary: Implementation of the flashfunders workflow