luhnacy

A tiny (hopefully) gem that will automate some of the painful tasks of generating / validating strings of numbers based on the Luhn algorithm (e.g. credit card numbers, ID numbers).

Usage

To require:

require 'luhnacy'

To validate:

Luhnacy.valid?('49927398716')

To generate a string of 10 digits that satisfies the Luhn algorithm:

valid_string = Luhnacy.generate(10)

To generate a string of 10 digits that does not satisfy Luhn algorithm:

invalid_string = Luhnacy.generate(10, :invalid => true)

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Sources

Copyright © 2010 Rory McKinley. See LICENSE for details.