IsbnUtils 0.0.0.2 → 0.0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ class Isbn10DigitValidator < IsbnValidator
9
9
  def checkDigit
10
10
  @strippedIsbn = @isbn.gsub(/[^0-9a-z]/i,'')
11
11
  if @strippedIsbn.length != 10
12
- raise "error not an isbn"
12
+ raise "error not a 10 digit isbn"
13
13
  end
14
14
 
15
15
  end
@@ -6,22 +6,30 @@ class Isbn13DigitValidator < IsbnValidator
6
6
  def initialize(isbn13)
7
7
  @isbn = isbn13
8
8
  end
9
+
10
+ def checkDigit
11
+ @strippedIsbn = @isbn.gsub(/[^0-9a-z]/i,'')
12
+ if @strippedIsbn.length != 13
13
+ raise "error not a 13 digit isbn"
14
+ end
15
+
16
+ end
9
17
 
10
18
 
11
- def isIsbn13Valid
19
+ def validateIsbn
12
20
  check = 0
13
21
  i = 0
14
22
  while i < 12 do
15
- check = check + @isbn[i].to_i
23
+ check = check + @strippedIsbn[i].to_i
16
24
  i = i + 2
17
25
  end
18
26
 
19
27
  i = 1
20
28
  while i < 12 do
21
- check = check + 3* @isbn[i].to_i
29
+ check = check + 3* @strippedIsbn[i].to_i
22
30
  i = i + 2
23
31
  end
24
- check = check + @isbn[12].to_i
32
+ check = check + @strippedIsbn[12].to_i
25
33
  return check % 10 == 0;
26
34
  end
27
35
 
@@ -1,25 +1,24 @@
1
-
2
-
3
1
  #
4
2
  # The IsbnValidatorFactory is a validator factory class that returns either an object of Isbn10DigitValidator or Isbn13DigitValidator
5
- #
3
+ # IsbnValidatorFactory.getIsbnValidator("1402894627").validate() == true
4
+ # IsbnValidatorFactory.getIsbnValidator("1402894627").validate() == true
5
+ #
6
+
6
7
  require 'IsbnValidator'
7
8
  require 'Isbn10DigitValidator'
8
9
  require 'Isbn13DigitValidator'
9
10
  class IsbnValidatorFactory
10
11
 
11
-
12
-
13
12
  def self.getIsbnValidator(isbn)
14
13
 
15
14
  strippedIsbn = isbn.gsub(/[^0-9a-z]/i,'')
16
15
 
17
16
  if strippedIsbn.length == 10
18
17
  return Isbn10DigitValidator.new(strippedIsbn)
19
- elsif strippedIsbn.length == 14
18
+ elsif strippedIsbn.length == 13
20
19
  return Isbn13DigitValidator.new(strippedIsbn)
21
20
  else
22
- raise "error Invalid Isbn"
21
+ return false
23
22
  end
24
23
 
25
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: IsbnUtils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.2
4
+ version: 0.0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: