A lightweight implementation of the Luhn algorithm.
This gem is available in RubyGems. To install add the following to your Gemfile:
gem 'ruby-luhn'
And run bundle install
.
To generate the checksum for a number you can simply do
Luhn.generate('12345')
It uses base 10 by default, but you can change that easily:
Luhn.generate('123ABC', base: 16)
The MIT License (MIT)
Copyright (c) 2020 Jorge Leites