library_stdnums 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/library_stdnums.rb +5 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/library_stdnums.rb
CHANGED
@@ -20,6 +20,7 @@ module StdNum
|
|
20
20
|
# @return [String] the one-character checkdigit
|
21
21
|
def self.checkdigit isbn
|
22
22
|
isbn = StdNum.extractNumber isbn
|
23
|
+
return nil unless isbn
|
23
24
|
size = isbn.size
|
24
25
|
return nil unless size == 10 or size == 13
|
25
26
|
checkdigit = 0
|
@@ -46,6 +47,7 @@ module StdNum
|
|
46
47
|
# @return [Boolean] Whether or not the checkdigit is correct
|
47
48
|
def self.valid? isbn
|
48
49
|
isbn = StdNum.extractNumber isbn
|
50
|
+
return false unless isbn
|
49
51
|
size = isbn.size
|
50
52
|
return false unless (size == 10 or size == 13)
|
51
53
|
return isbn[-1..-1] == self.checkdigit(isbn)
|
@@ -59,6 +61,7 @@ module StdNum
|
|
59
61
|
# @return [String] The converted 13-character ISBN, nil if something looks wrong, or whatever was passed in if it already looked like a 13-digit ISBN
|
60
62
|
def self.convert_to_13 isbn
|
61
63
|
isbn = StdNum.extractNumber isbn
|
64
|
+
return nil unless isbn
|
62
65
|
size = isbn.size
|
63
66
|
return isbn if size == 13
|
64
67
|
return nil unless size == 10
|
@@ -74,6 +77,7 @@ module StdNum
|
|
74
77
|
# @return [String] The converted 10-character ISBN, nil if something looks wrong, or whatever was passed in if it already looked like a 10-digit ISBN
|
75
78
|
def self.convert_to_10 isbn
|
76
79
|
isbn = StdNum.extractNumber isbn
|
80
|
+
return nil unless isbn
|
77
81
|
size = isbn.size
|
78
82
|
return isbn if size == 10
|
79
83
|
return nil unless size == 13
|
@@ -92,6 +96,7 @@ module StdNum
|
|
92
96
|
|
93
97
|
def self.allNormalizedValues isbn
|
94
98
|
isbn = StdNum.extractNumber isbn
|
99
|
+
return [] unless isbn
|
95
100
|
case isbn.size
|
96
101
|
when 10
|
97
102
|
return [isbn, self.convert_to_13(isbn)]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: library_stdnums
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Dueber
|