Class: RussianPost::Captcha::Patterns

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_post/captcha/patterns.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Patterns

Returns a new instance of Patterns.



14
15
16
# File 'lib/russian_post/captcha/patterns.rb', line 14

def initialize(file)
  @patterns = load_patterns(file)
end

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



4
5
6
# File 'lib/russian_post/captcha/patterns.rb', line 4

def patterns
  @patterns
end

Class Method Details

.built_inObject



8
9
10
# File 'lib/russian_post/captcha/patterns.rb', line 8

def built_in
  @builtin_patterns ||= RussianPost::Captcha::Patterns.new(File.expand_path('characters.dat', File.dirname(__FILE__)))
end

Instance Method Details

#add(pattern) ⇒ Object



22
23
24
# File 'lib/russian_post/captcha/patterns.rb', line 22

def add(pattern)
  @patterns << pattern
end

#each(&block) ⇒ Object



18
19
20
# File 'lib/russian_post/captcha/patterns.rb', line 18

def each(&block)
  @patterns.each(&block)
end

#find(image, x, y) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/russian_post/captcha/patterns.rb', line 26

def find(image, x, y)
  each do |pattern|
    return pattern if pattern.match?(image, x, y)
  end

  return false
end