library_stdnums 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/VERSION +1 -1
- data/lib/library_stdnums.rb +14 -3
- metadata +5 -4
data/CHANGES
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/library_stdnums.rb
CHANGED
@@ -117,19 +117,30 @@ module StdNum
|
|
117
117
|
# @return [String] the one-character checkdigit
|
118
118
|
def self.checkdigit issn
|
119
119
|
issn = StdNum.extractNumber issn
|
120
|
-
return nil unless issn.size == 8
|
120
|
+
return nil unless issn and issn.size == 8
|
121
121
|
digits = issn[0..6].split(//).map {|i| i.to_i}
|
122
122
|
checkdigit = 0
|
123
123
|
(0..6).each do |i|
|
124
124
|
checkdigit += digits[i] * (8 - i)
|
125
125
|
end
|
126
126
|
checkdigit = checkdigit % 11
|
127
|
-
return 0 if checkdigit == 0
|
127
|
+
return '0' if checkdigit == 0
|
128
128
|
checkdigit = 11 - checkdigit
|
129
129
|
return 'X' if checkdigit == 10
|
130
130
|
return checkdigit.to_s
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
|
+
# Check to see if the checkdigit is correct
|
134
|
+
# @param [String] isbn The ISSN (we'll try to clean it up if possible)
|
135
|
+
# @return [Boolean] Whether or not the checkdigit is correct
|
136
|
+
def self.valid? issn
|
137
|
+
issn = StdNum.extractNumber issn
|
138
|
+
return false unless issn
|
139
|
+
size = issn.size
|
140
|
+
return false unless (size == 8)
|
141
|
+
return issn[-1..-1] == self.checkdigit(issn)
|
142
|
+
end
|
143
|
+
|
133
144
|
|
134
145
|
end
|
135
146
|
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
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: 2010-
|
18
|
+
date: 2010-12-02 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ extra_rdoc_files:
|
|
58
58
|
files:
|
59
59
|
- .document
|
60
60
|
- .gitignore
|
61
|
+
- CHANGES
|
61
62
|
- LICENSE
|
62
63
|
- README.rdoc
|
63
64
|
- Rakefile
|