# File lib/isbn-converter.rb, line 28 def to10(isbn) isbn = clean(isbn) return nil unless isbn.length == 13 && isbn[0..2] != "979" new_isbn = isbn.chop[3..(isbn.length - 1)] check = 0 10.downto(2) { |n| check += new_isbn[(10 - n)..(10 - n)].to_i * n } check = 11 - (check % 11) check = "X" if check == 10 new_isbn + check.to_s end