Class: Goggles::Comparison
- Inherits:
-
Object
- Object
- Goggles::Comparison
- Defined in:
- lib/goggles/comparison.rb
Overview
Generates a diff image and data file from two images.
Results are saved to a new directory derived from the configured directory setting,
a description given to `Watir::Browser.grab_screenshot`, browser size, and the
browsers used to take the screenshots.
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#fuzzing ⇒ Object
readonly
Returns the value of attribute fuzzing.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#results_dir ⇒ Object
readonly
Returns the value of attribute results_dir.
Instance Method Summary collapse
-
#cut_to_common_size ⇒ nil
Sizes comparable screenshots to a common height and width.
-
#find_common_height(array) ⇒ Fixnum
Finds the smallest second element for all arrays in the given array.
-
#find_common_width(array) ⇒ Fixnum
Finds the smallest first element for all arrays in the given array.
-
#find_comparable(description) ⇒ Array<String>
Finds comparable screenshots for sizing and comparing.
-
#highlight_differences ⇒ nil
Generates diff images for comparable screenshots.
-
#initialize(config) ⇒ Comparison
constructor
A new instance of Comparison.
-
#make! ⇒ nil
Sizes and compare screenshots.
Constructor Details
#initialize(config) ⇒ Comparison
Returns a new instance of Comparison.
32 33 34 35 36 37 |
# File 'lib/goggles/comparison.rb', line 32 def initialize config @directory = config.directory @fuzzing = config.fuzzing @color = config.color @groups = config.groups end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
30 31 32 |
# File 'lib/goggles/comparison.rb', line 30 def color @color end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
30 31 32 |
# File 'lib/goggles/comparison.rb', line 30 def directory @directory end |
#fuzzing ⇒ Object (readonly)
Returns the value of attribute fuzzing.
30 31 32 |
# File 'lib/goggles/comparison.rb', line 30 def fuzzing @fuzzing end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
30 31 32 |
# File 'lib/goggles/comparison.rb', line 30 def groups @groups end |
#results_dir ⇒ Object
Returns the value of attribute results_dir.
30 31 32 |
# File 'lib/goggles/comparison.rb', line 30 def results_dir @results_dir end |
Instance Method Details
#cut_to_common_size ⇒ nil
Sizes comparable screenshots to a common height and width.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/goggles/comparison.rb', line 54 def cut_to_common_size groups.each_with_object([]) do |group, sizes| collection = find_comparable group collection.each do |img| File.open(img, 'rb'){ |file| sizes << read_size(file) } end cut! collection, sizes end end |
#find_common_height(array) ⇒ Fixnum
Finds the smallest second element for all arrays in the given array. This is
the screenshot height attribute. Used for resizing.
106 107 108 |
# File 'lib/goggles/comparison.rb', line 106 def find_common_height array array.collect(&:last).sort.first end |
#find_common_width(array) ⇒ Fixnum
Finds the smallest first element for all arrays in the given array. This is
the screenshot width attribute. Used for resizing.
95 96 97 |
# File 'lib/goggles/comparison.rb', line 95 def find_common_width array array.collect(&:first).sort.first end |
#find_comparable(description) ⇒ Array<String>
Finds comparable screenshots for sizing and comparing.
84 85 86 |
# File 'lib/goggles/comparison.rb', line 84 def find_comparable description Dir.glob("#{directory}/*.png").grep(/#{description}_/).sort end |
#highlight_differences ⇒ nil
Generates diff images for comparable screenshots.
71 72 73 74 75 76 |
# File 'lib/goggles/comparison.rb', line 71 def highlight_differences groups.each do |desc| ensure_result_directory desc find_comparable(desc).combination(2).to_a.each { |imgs| diff imgs[0], imgs[1] } end end |
#make! ⇒ nil
Sizes and compare screenshots.
44 45 46 47 |
# File 'lib/goggles/comparison.rb', line 44 def make! cut_to_common_size highlight_differences end |