Class: Kamcaptcha::Generator::WordGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/kamcaptcha/generator.rb

Direct Known Subclasses

DictionaryWordGenerator, RandomWordGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ WordGenerator

Returns a new instance of WordGenerator.



13
14
15
16
17
18
19
20
21
22
# File 'lib/kamcaptcha/generator.rb', line 13

def initialize(length)
  if length.to_s =~ /^(\d+)$/
    @min = @max = $1.to_i
  elsif length =~ /^(\d+)-(\d+)$/
    @min = [$1.to_i, $2.to_i].min
    @max = [$1.to_i, $2.to_i].max
  else
    raise ArgumentError.new("Invalid word length specified: #{length}")
  end
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



11
12
13
# File 'lib/kamcaptcha/generator.rb', line 11

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



11
12
13
# File 'lib/kamcaptcha/generator.rb', line 11

def min
  @min
end