Module: StdNum::ISSN
- Extended by:
- Helpers
- Defined in:
- lib/library_stdnums.rb
Overview
Validate and and normalize ISSNs
Constant Summary
Constants included from Helpers
Class Method Summary (collapse)
-
+ (String) checkdigit(issn, preprocessed = false)
Compute the checkdigit of an ISSN.
-
+ (String?) normalize(rawissn)
Make sure it's valid, remove the dashes, uppercase the X, and return.
-
+ (Boolean) valid?(issn, preprocessed = false)
Check to see if the checkdigit is correct.
Methods included from Helpers
extractNumber, reduce_to_basics
Class Method Details
+ (String) checkdigit(issn, preprocessed = false)
Compute the checkdigit of an ISSN
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/library_stdnums.rb', line 174 def self.checkdigit issn, preprocessed = false issn = reduce_to_basics issn, 8 unless preprocessed return nil unless issn digits = issn[0..6].split(//).map {|i| i.to_i} checkdigit = 0 (0..6).each do |i| checkdigit += digits[i] * (8 - i) end checkdigit = checkdigit % 11 return '0' if checkdigit == 0 checkdigit = 11 - checkdigit return 'X' if checkdigit == 10 return checkdigit.to_s end |
+ (String?) normalize(rawissn)
Make sure it's valid, remove the dashes, uppercase the X, and return
206 207 208 209 210 211 212 213 |
# File 'lib/library_stdnums.rb', line 206 def self.normalize rawissn issn = reduce_to_basics rawissn, 8 if issn and valid?(issn, true) return issn else return nil end end |
+ (Boolean) valid?(issn, preprocessed = false)
Check to see if the checkdigit is correct
195 196 197 198 199 |
# File 'lib/library_stdnums.rb', line 195 def self.valid? issn, preprocessed = false issn = reduce_to_basics issn, 8 unless preprocessed return false unless issn return issn[-1..-1] == self.checkdigit(issn, true) end |