library_stdnums 1.2.0 → 1.3.0
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.
- data/ChangeLog.md +4 -0
- data/lib/library_stdnums.rb +21 -4
- data/lib/library_stdnums/version.rb +1 -1
- metadata +3 -3
data/ChangeLog.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
* 1.3.0 (2013.05.24)
|
2
|
+
* Added #at_least_trying? to do a basic syntax check for ISSN/ISBN
|
3
|
+
* Overload #valid? for ISBN/ISSN such that it returns 'nil' for bad syntax and
|
4
|
+
'false' for good-looking syntax, but bad checkdigit
|
1
5
|
* 1.2.0 (2012.07.24)
|
2
6
|
* Added a bunch of tests for LCCN normalization from perl module Business::LCCN
|
3
7
|
(http://search.cpan.org/~anirvan/Business-LCCN/)
|
data/lib/library_stdnums.rb
CHANGED
@@ -51,6 +51,12 @@ module StdNum
|
|
51
51
|
# Validate, convert, and normalize ISBNs (10-digit or 13-digit)
|
52
52
|
module ISBN
|
53
53
|
extend Helpers
|
54
|
+
|
55
|
+
# Does it even look like an ISBN?
|
56
|
+
def self.at_least_trying? isbn
|
57
|
+
return !(reduce_to_basics(isbn, [10,13]))
|
58
|
+
end
|
59
|
+
|
54
60
|
|
55
61
|
# Compute check digits for 10 or 13-digit ISBNs. See algorithm at
|
56
62
|
# http://en.wikipedia.org/wiki/International_Standard_Book_Number
|
@@ -86,11 +92,13 @@ module StdNum
|
|
86
92
|
# Check to see if the checkdigit is correct
|
87
93
|
# @param [String] isbn The ISBN (we'll try to clean it up if possible)
|
88
94
|
# @param [Boolean] preprocessed Set to true if the ISBN has already been through reduce_to_basics
|
89
|
-
# @return [Boolean] Whether or not the checkdigit is correct
|
95
|
+
# @return [Boolean] Whether or not the checkdigit is correct. Sneakily, return 'nil' for
|
96
|
+
# values that don't even look like ISBNs, and 'false' for those that look possible but
|
97
|
+
# don't normalize / have bad checkdigits
|
90
98
|
def self.valid? isbn, preprocessed = false
|
91
99
|
return nil if isbn.nil?
|
92
100
|
isbn = reduce_to_basics(isbn, [10,13]) unless preprocessed
|
93
|
-
return
|
101
|
+
return nil unless isbn
|
94
102
|
return false unless isbn[-1..-1] == self.checkdigit(isbn, true)
|
95
103
|
return true
|
96
104
|
end
|
@@ -171,6 +179,13 @@ module StdNum
|
|
171
179
|
module ISSN
|
172
180
|
extend Helpers
|
173
181
|
|
182
|
+
|
183
|
+
# Does it even look like an ISSN?
|
184
|
+
def self.at_least_trying? isbn
|
185
|
+
return !(reduce_to_basics(issn, 8))
|
186
|
+
end
|
187
|
+
|
188
|
+
|
174
189
|
# Compute the checkdigit of an ISSN
|
175
190
|
# @param [String] issn The ISSN (we'll try to clean it up if possible)
|
176
191
|
# @param [Boolean] preprocessed Set to true if the number has already been through reduce_to_basic
|
@@ -195,11 +210,13 @@ module StdNum
|
|
195
210
|
# Check to see if the checkdigit is correct
|
196
211
|
# @param [String] issn The ISSN (we'll try to clean it up if possible)
|
197
212
|
# @param [Boolean] preprocessed Set to true if the number has already been through reduce_to_basic
|
198
|
-
# @return [Boolean] Whether or not the checkdigit is correct
|
213
|
+
# @return [Boolean] Whether or not the checkdigit is correct. Sneakily, return 'nil' for
|
214
|
+
# values that don't even look like ISBNs, and 'false' for those that look possible but
|
215
|
+
# don't normalize / have bad checkdigits
|
199
216
|
|
200
217
|
def self.valid? issn, preprocessed = false
|
201
218
|
issn = reduce_to_basics issn, 8 unless preprocessed
|
202
|
-
return
|
219
|
+
return nil unless issn
|
203
220
|
return issn[-1..-1] == self.checkdigit(issn, true)
|
204
221
|
end
|
205
222
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: library_stdnums
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
91
|
+
rubygems_version: 1.8.23
|
92
92
|
signing_key:
|
93
93
|
specification_version: 3
|
94
94
|
summary: Normalize and validate ISBN / ISSN/ LCCN
|