Sha256: 266bb45ea147f76b6146c6b0f4212b664cd7db7d5039a472fceef14523ca9d97
Contents?: true
Size: 433 Bytes
Versions: 106
Compression:
Stored size: 433 Bytes
Contents
module BookKeeping VERSION = 1 end class IsbnVerifier def self.valid?(str) return false unless /\A\d-?\d{3}-?\d{5}-?[\dX]\z/.match(str) result = str .gsub("-", "") .chars .map { |char| char.gsub("X","10") } .zip(10.downto(1)) .map { |number, index| number.to_i * index } .reduce(0){ |sum, digit| sum + digit } result % 11 == 0 end end
Version data entries
106 entries across 106 versions & 1 rubygems