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

Version Path
trackler-2.2.1.180 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.179 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.178 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.177 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.176 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.175 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.174 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.173 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.172 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.171 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.170 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.169 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.167 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.166 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.165 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.164 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.163 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.162 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.161 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb
trackler-2.2.1.160 tracks/ruby/exercises/isbn-verifier/.meta/solutions/isbn_verifier.rb