Class: Imatcher::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/imatcher/matcher.rb

Overview

Matcher contains information about compare mode

Constant Summary collapse

MODES =
{
  rgb: 'RGB',
  delta: 'Delta',
  grayscale: 'Grayscale'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Matcher



16
17
18
19
# File 'lib/imatcher/matcher.rb', line 16

def initialize(options = {})
  mode_type = options.delete(:mode) || :rgb
  @mode = Modes.const_get(MODES[mode_type]).new(options)
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



14
15
16
# File 'lib/imatcher/matcher.rb', line 14

def mode
  @mode
end

#thresholdObject (readonly)

Returns the value of attribute threshold.



14
15
16
# File 'lib/imatcher/matcher.rb', line 14

def threshold
  @threshold
end

Instance Method Details

#compare(a, b) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/imatcher/matcher.rb', line 21

def compare(a, b)
  a = Image.from_file(a) unless a.is_a?(Image)
  b = Image.from_file(b) unless b.is_a?(Image)
  raise SizesMismatchError,
        "Size mismatch: first image size: " \
        "#{a.width}x#{a.height}, " \
        "second image size: " \
        "#{b.width}x#{b.height}" unless a.sizes_match?(b)

  mode.compare(a, b)
end