library_stdnums 0.2.1 → 0.2.2

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.
Files changed (4) hide show
  1. data/CHANGES +7 -0
  2. data/VERSION +1 -1
  3. data/lib/library_stdnums.rb +14 -3
  4. metadata +5 -4
data/CHANGES ADDED
@@ -0,0 +1,7 @@
1
+ 0.2.2
2
+ Added ISSN.valid?
3
+ Fixed error in ISSN.checksum when checksum was zero (was returning integer instead of string '0')
4
+ 0.2.1
5
+ Oops. Forgot to check to make sure there are *any* digits in the ISBN. fixed.
6
+ 0.2.0
7
+ Added allNormalizedValues for ISBN
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
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-10-13 00:00:00 -04:00
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