Sha256: ecbde1d5f66c031b5fd598e73bcd57d7edec601c36dc09e7bdf27ac1c45ebd39
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
module LooksGood class Image attr_accessor :file_name, :path, :image attr_reader :type def initialize image, file_name @file_name = file_name @image = image end def save(type = :reference) save_path = path(type) FileUtils::mkdir_p(File.dirname(save_path)) unless File.exists?(save_path) @image.write save_path save_path end def exists? File.exists?(path) end def path(type = :reference) @path = File.join(LooksGood::Configuration.path(type), @file_name) end end class ImageFromElement < Image def initialize(element, file_name) super(image, file_name) @element = element @image = capture_image end def verify_and_save LooksGood::Configuration.max_no_tries.times do comparable = capture_image matches = LooksGood::Comparison.new(self,Image.new(comparable,@file_name)).matches? if matches self.save puts "Saved #{self.path} as reference" return() else @image = comparable end end raise 'Could not save a stable image. This could be due to animations or page load times. Saved a reference image, delete it to re-try' end private def capture_image LooksGood::CaptureElement.capture(@element) end #TODO: make save a relevant subclass method end class ImageFromFile < Image def initialize(file_name) super(image, file_name) @image = Magick::Image.read(path).first end #TODO: make save a relevant subclass method end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
looks_good-1.0.1 | lib/looks_good/image.rb |
looks_good-1.0.0 | lib/looks_good/image.rb |