Sha256: 413273216b4f62d2946a605f61aae15d5089bc9a3a07ce69d1eb81c11ae1eafc
Contents?: true
Size: 406 Bytes
Versions: 1
Compression:
Stored size: 406 Bytes
Contents
class CheckDigit def check(str) str = str.strip.upcase values = str.chars.map do |char| case char when '<' 0 when 'A'..'Z' char.ord - 65 + 10 when '0'..'9' char.ord - 48 else raise "Unexpected character '#{char}'" end end return (values.zip([7,3,1].cycle).map{|(v,w)| v * w}.reduce(:+) % 10).to_s end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
verified-0.1 | lib/verified/checkdigit.rb |