Class: RussianPost::Captcha::Pattern
- Inherits:
-
Object
- Object
- RussianPost::Captcha::Pattern
- Defined in:
- lib/russian_post/captcha/pattern.rb
Constant Summary collapse
- TARGET_MATCH_RATE =
1.0
Instance Attribute Summary collapse
-
#character ⇒ Object
readonly
Returns the value of attribute character.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
-
#initialize(points, character) ⇒ Pattern
constructor
A new instance of Pattern.
- #match?(image, x, y) ⇒ Boolean
Constructor Details
#initialize(points, character) ⇒ Pattern
Returns a new instance of Pattern.
8 9 10 |
# File 'lib/russian_post/captcha/pattern.rb', line 8 def initialize(points, character) @points, @character = points, character end |
Instance Attribute Details
#character ⇒ Object (readonly)
Returns the value of attribute character.
6 7 8 |
# File 'lib/russian_post/captcha/pattern.rb', line 6 def character @character end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
6 7 8 |
# File 'lib/russian_post/captcha/pattern.rb', line 6 def points @points end |
Instance Method Details
#match?(image, x, y) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |