IsbnUtils 0.0.0.3 → 0.0.0.4

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.
@@ -1,7 +1,6 @@
1
1
  require 'IsbnValidator'
2
2
  class Isbn10DigitValidator < IsbnValidator
3
3
 
4
-
5
4
  def initialize(isbn10)
6
5
  @isbn = isbn10
7
6
  end
@@ -9,9 +8,9 @@ class Isbn10DigitValidator < IsbnValidator
9
8
  def checkDigit
10
9
  @strippedIsbn = @isbn.gsub(/[^0-9a-z]/i,'')
11
10
  if @strippedIsbn.length != 10
12
- raise "error not a 10 digit isbn"
11
+ return false
13
12
  end
14
-
13
+ return true
15
14
  end
16
15
 
17
16
 
@@ -7,29 +7,31 @@ class Isbn13DigitValidator < IsbnValidator
7
7
  @isbn = isbn13
8
8
  end
9
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
10
+
11
+ def checkDigit
12
+ @strippedIsbn = @isbn.gsub(/[^0-9a-z]/i,'')
13
+ if @strippedIsbn.length != 13
14
+ return false
15
+ end
16
+
17
+ return true
18
+ end
17
19
 
18
20
 
19
21
  def validateIsbn
20
22
  check = 0
21
23
  i = 0
22
24
  while i < 12 do
23
- check = check + @strippedIsbn[i].to_i
25
+ check = check + @isbn[i].to_i
24
26
  i = i + 2
25
27
  end
26
28
 
27
29
  i = 1
28
30
  while i < 12 do
29
- check = check + 3* @strippedIsbn[i].to_i
31
+ check = check + 3* @isbn[i].to_i
30
32
  i = i + 2
31
33
  end
32
- check = check + @strippedIsbn[12].to_i
34
+ check = check + @isbn[12].to_i
33
35
  return check % 10 == 0;
34
36
  end
35
37
 
data/lib/IsbnValidator.rb CHANGED
@@ -1,4 +1,4 @@
1
- #
1
+
2
2
  # The IsbnValidator class defines a template method called validate , which represent
3
3
  # a workflow to follow. The validate method calls checkDigit and validateIsbn methods
4
4
  # which have its custom implementation in the subclasses.
@@ -11,8 +11,10 @@ class IsbnValidator
11
11
  def validateIsbn; raise METHOD_MISSING; end
12
12
 
13
13
  def validate
14
- checkDigit()
15
- result = validateIsbn()
14
+ result = checkDigit()
15
+ if result?
16
+ result = validateIsbn()
17
+ end
16
18
  return result
17
19
  end
18
20
 
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.3
4
+ version: 0.0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: