Sha256: 5818129c3a68deda3ba80c9ac76e18ffc83e9e3c0597d00188ccfc21e32ae792

Contents?: true

Size: 276 Bytes

Versions: 3

Compression:

Stored size: 276 Bytes

Contents

require "jan/parser"

class Jan
  module CheckDigitCalculator
    module_function

    def calculate(body)
      code = body.to_s + "x"
      digit = 10 - (Parser.even_digits(code).reduce(&:+) * 3 + Parser.odd_digits(code).reduce(&:+)) % 10
      digit % 10
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jan-0.0.3 lib/jan/check_digit_calculator.rb
jan-0.0.2 lib/jan/check_digit_calculator.rb
jan-0.0.1 lib/jan/check_digit_calculator.rb