class RussianPost::Captcha::Pattern

Constants

TARGET_MATCH_RATE

Attributes

character[R]
points[R]

Public Class Methods

new(points, character) click to toggle source
# File lib/russian_post/captcha/pattern.rb, line 8
def initialize(points, character)
  @points, @character = points, character
end

Public Instance Methods

match?(image, x, y) click to toggle source
# File lib/russian_post/captcha/pattern.rb, line 12
def match?(image, x, y)
  matching = 0

  points.each do |px, py|
    cx, cy = x + px, y + py

    break if cx >= image.width || cy >= image.height || image[cx, cy] == 255

    matching += 1
  end

  matching / points.size >= TARGET_MATCH_RATE
end