Class: Kontrast::PageComparator
- Inherits:
-
Object
- Object
- Kontrast::PageComparator
- Includes:
- Magick
- Defined in:
- lib/kontrast/page_comparator.rb
Instance Attribute Summary collapse
-
#diffs ⇒ Object
readonly
Returns the value of attribute diffs.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #diff(test) ⇒ Object
-
#initialize ⇒ PageComparator
constructor
A new instance of PageComparator.
- #production_image_path(test) ⇒ Object
- #test_image_path(test) ⇒ Object
Constructor Details
#initialize ⇒ PageComparator
Returns a new instance of PageComparator.
7 8 9 10 11 12 |
# File 'lib/kontrast/page_comparator.rb', line 7 def initialize @path = Kontrast.path # This is where failed diffs will be stored @diffs = {} end |
Instance Attribute Details
#diffs ⇒ Object (readonly)
Returns the value of attribute diffs.
5 6 7 |
# File 'lib/kontrast/page_comparator.rb', line 5 def diffs @diffs end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/kontrast/page_comparator.rb', line 5 def path @path end |
Instance Method Details
#diff(test) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kontrast/page_comparator.rb', line 22 def diff(test) image_helper = Kontrast::ImageHelper.new( test_image_path(test), production_image_path(test), ) # In order for images to be diff'ed, they need to have the same dimensions print "Cropping... " image_helper.crop(test.width) diff = image_helper.compare(test.to_s, "diff.png") # If the images are different, let the class know about it so that it gets added to the manifest if diff > 0 @diffs["#{test}"] = { type: 'page', width: test.width, name: test.name, diff: diff, } end end |
#production_image_path(test) ⇒ Object
18 19 20 |
# File 'lib/kontrast/page_comparator.rb', line 18 def production_image_path(test) return "#{@path}/#{test}/production.png" end |
#test_image_path(test) ⇒ Object
14 15 16 |
# File 'lib/kontrast/page_comparator.rb', line 14 def test_image_path(test) return "#{@path}/#{test}/test.png" end |