Class: Isbn13DigitValidator
Constant Summary
IsbnValidator::METHOD_MISSING
Instance Method Summary
collapse
#validate
Constructor Details
Returns a new instance of Isbn13DigitValidator.
6
7
8
|
# File 'lib/Isbn13DigitValidator.rb', line 6
def initialize(isbn13)
@isbn = isbn13
end
|
Instance Method Details
#checkDigit ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/Isbn13DigitValidator.rb', line 11
def checkDigit
@strippedIsbn = @isbn.gsub(/[^0-9a-z]/i,'')
if @strippedIsbn.length != 13
return false
end
return true
end
|
#validateIsbn ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/Isbn13DigitValidator.rb', line 21
def validateIsbn
check = 0
i = 0
while i < 12 do
check = check + @isbn[i].to_i
i = i + 2
end
i = 1
while i < 12 do
check = check + 3* @isbn[i].to_i
i = i + 2
end
check = check + @isbn[12].to_i
return check % 10 == 0;
end
|