class Imatcher::Matcher
Matcher
contains information about compare mode
Constants
- MODES
Attributes
mode[R]
threshold[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/imatcher/matcher.rb, line 16 def initialize(options = {}) mode_type = options.delete(:mode) || :rgb fail ArgumentError, "Undefined mode: #{ mode_type }" unless MODES.keys.include?(mode_type) @mode = Modes.const_get(MODES[mode_type]).new(options) end
Public Instance Methods
compare(a, b)
click to toggle source
# File lib/imatcher/matcher.rb, line 22 def compare(a, b) a = Image.from_file(a) unless a.is_a?(Image) b = Image.from_file(b) unless b.is_a?(Image) fail SizesMismatchError, "Size mismatch: first image size: " \ "#{a.width}x#{a.height}, " \ "second image size: " \ "#{b.width}x#{b.height}" unless a.sizes_match?(b) image_area = Rectangle.new(0, 0, a.width - 1, a.height - 1) unless mode.exclude_rect.nil? fail ArgumentError, "Bounds must be in image" unless image_area.contains?(mode.exclude_rect) end unless mode.include_rect.nil? fail ArgumentError, "Bounds must be in image" unless image_area.contains?(mode.include_rect) unless mode.exclude_rect.nil? fail ArgumentError, "Included area must contain excluded" unless mode.include_rect.contains?(mode.exclude_rect) end end mode.compare(a, b) end