Security identifiers validation library for Ruby.
Currently supports
- ISIN
- CUSIP
- SEDOL
Validates:
- Format
- Check Digit
Add this line to your application's Gemfile:
gem 'security_identifiers'
And then execute:
$ bundle
Or install it yourself as:
$ gem install security_identifiers
To validate an ISIN
isin = SecurityIdentifiers::ISIN.new('US0378331005')
isin.valid? # => true
or with an invalid identifier
isin = SecurityIdentifiers::ISIN.new('S0378331005') # => raises SecurityIdentifiers::InvalidFormat
Now you can validate
isin.valid? # => true
The same method applies to CUSIPs and SEDOLs.
CUSIPs and SEDOLs also support converting these identifiers to ISINs.
cusip = SecurityIdentifiers::CUSIP.new('125509BG3')
cusip.to_isin('US') # => SecurityIdentifiers::ISIN
Includes custom validators for use in ActiveModel/ActiveRecord
class Security
include ActiveModel::Validations
include SecurityIdentifiers::Validations
attr_accessor :cusip, :isin, :sedol
def initialize(options = {})
@cusip = options[:cusip]
@isin = options[:isin]
@sedol = options[:sedol]
end
validates :cusip, cusip: true, allow_blank: true
validates :isin, isin: true, allow_blank: true
validates :sedol, sedol: true, allow_blank: true
end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request