Repository is archived
No commit activity in last 3 years
No release in over 3 years
CUSIP-style luhn mod N
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 10.0
~> 3.0
 Project Readme

cusip_style_luhn_mod_n CircleCI Gem Version npm version

CUSIP-style luhn mod N algorithm based on https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/checkdigit/CUSIPCheckDigit.html and https://en.wikipedia.org/wiki/Luhn_mod_N_algorithm

Installation

Ruby:

Add this line to your application's Gemfile and run bundle:

gem 'cusip_style_luhn_mod_n'

JavaScript:

npm i cusip_style_luhn_mod_n --save

Usage

Ruby:

# Check validity of check digit:
CUSIPStyleLuhnModN.valid?("A1B2C5")
=> true

CUSIPStyleLuhnModN.valid?("A1B2C4")
=> false

# Generate check digit
CUSIPStyleLuhnModN.check_digit("A1B2C")
=> 5

JavaScript:

// Check validity of check digit:
CUSIPStyleLuhnModN.isValid("A1B2C5")
=> true

CUSIPStyleLuhnModN.isValid("A1B2C4")
=> false

// Generate check digit
CUSIPStyleLuhnModN.checkDigit("A1B2C")
=> 5

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.