5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/aritcaptcha/calculation.rb', line 5
def self.generate_calculation number1, number2, operator, &block
return [nil, nil] if operator == "/" and number1.zero? or number2.zero?
number1 = rand(number1)
number2 = rand(number2)
equation = "#{number1} #{operator} #{number2}"
result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
if result.infinite?
number1 = rand(number1)
number2 = rand(number2)
result = eval("#{number1.to_f} #{operator} #{number2.to_f}")
end
result = (result == result.floor) ? result.to_i : result
[equation, result]
end
|