Class: Imatcher::Matcher
- Inherits:
-
Object
- Object
- Imatcher::Matcher
- 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
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #compare(a, b) ⇒ Object
-
#initialize(options = {}) ⇒ Matcher
constructor
A new instance of Matcher.
Constructor Details
#initialize(options = {}) ⇒ Matcher
16 17 18 19 |
# File 'lib/imatcher/matcher.rb', line 16 def initialize( = {}) mode_type = .delete(:mode) || :rgb @mode = Modes.const_get(MODES[mode_type]).new() end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
14 15 16 |
# File 'lib/imatcher/matcher.rb', line 14 def mode @mode end |
#threshold ⇒ Object (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
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 |