library_stdnums 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/VERSION +1 -1
- data/lib/library_stdnums.rb +5 -2
- data/spec/library_stdnums_spec.rb +4 -0
- metadata +4 -4
data/CHANGES
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/library_stdnums.rb
CHANGED
@@ -33,12 +33,15 @@ module StdNum
|
|
33
33
|
return 'X' if checkdigit == 10
|
34
34
|
return checkdigit.to_s
|
35
35
|
else # size == 13
|
36
|
+
checkdigit = 0
|
36
37
|
digits = isbn[0..11].split(//).map {|i| i.to_i}
|
37
38
|
6.times do
|
38
39
|
checkdigit += digits.shift
|
39
40
|
checkdigit += digits.shift * 3
|
40
41
|
end
|
41
|
-
|
42
|
+
check = 10 - (checkdigit % 10)
|
43
|
+
check = 0 if check == 10
|
44
|
+
return check.to_s
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
@@ -155,7 +158,7 @@ module StdNum
|
|
155
158
|
pre = $1
|
156
159
|
post = $2
|
157
160
|
return nil unless post =~ /^\d+$/ # must be all digits
|
158
|
-
return "%s%06d" % [pre, post]
|
161
|
+
return "%s%06d" % [pre, post.to_i]
|
159
162
|
end
|
160
163
|
return str
|
161
164
|
end
|
@@ -49,6 +49,10 @@ describe "ISBN" do
|
|
49
49
|
StdNum::ISBN.checkdigit('9780306406157').should.equal '7'
|
50
50
|
end
|
51
51
|
|
52
|
+
it "computes a 13-digit checksum that is 0" do
|
53
|
+
StdNum::ISBN.checkdigit('9783837612950').should.equal '0'
|
54
|
+
end
|
55
|
+
|
52
56
|
it "finds a good number valid" do
|
53
57
|
StdNum::ISBN.valid?('9780306406157').should.equal true
|
54
58
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bill Dueber
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-04-11 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|