Sha256: eaba7a8f194285a70eb5747b4d4d053a1e1fb50c331db958e80d71671b2952ee

Contents?: true

Size: 287 Bytes

Versions: 3

Compression:

Stored size: 287 Bytes

Contents

require "jan/parser"

class Jan < ::String
  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.1.0 lib/jan/check_digit_calculator.rb
jan-0.0.5 lib/jan/check_digit_calculator.rb
jan-0.0.4 lib/jan/check_digit_calculator.rb