Class: Check::CheckDigit
- Inherits:
-
Object
- Object
- Check::CheckDigit
- Defined in:
- lib/verified/check.rb
Instance Method Summary collapse
Instance Method Details
#check_calc(str) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/verified/check.rb', line 53 def check_calc(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 |