Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Validate securities identification numbers (ISIN, CUSIP, SEDOL, FIGI, CIK) with ease!

License

NotificationsYou must be signed in to change notification settings

svyatov/sec_id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gem VersionBuild StatusMaintainabilityTest Coverage

Validate securities identification numbers with ease!

Check-digit calculation is also available.

Currently supported standards:ISIN,CUSIP,SEDOL,FIGI,CIK.

Work in progress:IBAN.

Installation

Add this line to your application's Gemfile:

gem'sec_id','~> 4.1'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sec_id

Usage

Base API

Base API has 4 main methods which can be used both on class level and on instance level:

  • valid? - never raises any errors, always returnstrue orfalse,numbers without the check-digit will returnfalse

    # class levelSecId::ISIN.valid?('US5949181045')# => trueSecId::ISIN.valid?('US594918104')# => false# instance levelisin=SecId::ISIN.new('US5949181045')isin.valid?# => true
  • valid_format? - never raises any errors, always returnstrue orfalse,numbers without the check-digit but in valid format will returntrue

    # class levelSecId::ISIN.valid_format?('US5949181045')# => trueSecId::ISIN.valid_format?('US594918104')# => true# instance levelisin=SecId::ISIN.new('US594918104')isin.valid_format?# => true
  • restore! - restores check-digit and returns the full number,raises an error if number's format is invalid and thus check-digit is impossible to calculate

    # class levelSecId::ISIN.restore!('US594918104')# => 'US5949181045'# instance levelisin=SecId::ISIN.new('US5949181045')isin.restore!# => 'US5949181045'
  • check_digit andcalculate_check_digit - these are the same,but the former is used at class level for bravity,and the latter is used at instance level for clarity;it calculates and returns the check-digit if the number is validand raises an error otherwise.

    # class levelSecId::ISIN.check_digit('US594918104')# => 5# instance levelisin=SecId::ISIN.new('US594918104')isin.calculate_check_digit# => 5isin.check_digit# => nil

    ❗ Please note thatisin.check_digit returnsnil because#check_digitat instance level represents original check-digit of the number passed tonew,which in this example is missing and thus it'snil.

SecId::ISIN full example

# class levelSecId::ISIN.valid?('US5949181045')# => trueSecId::ISIN.valid_format?('US594918104')# => trueSecId::ISIN.restore!('US594918104')# => 'US5949181045'SecId::ISIN.check_digit('US594918104')# => 5# instance levelisin=SecId::ISIN.new('US5949181045')isin.full_number# => 'US5949181045'isin.country_code# => 'US'isin.nsin# => '594918104'isin.check_digit# => 5isin.valid?# => trueisin.valid_format?# => trueisin.restore!# => 'US5949181045'isin.calculate_check_digit# => 5isin.to_cusip# => #<SecId::CUSIP>

SecId::CUSIP full example

# class levelSecId::CUSIP.valid?('594918104')# => trueSecId::CUSIP.valid_format?('59491810')# => trueSecId::CUSIP.restore!('59491810')# => '594918104'SecId::CUSIP.check_digit('59491810')# => 5# instance levelcusip=SecId::CUSIP.new('594918104')cusip.full_number# => '594918104'cusip.cusip6# => '594918'cusip.issue# => '10'cusip.check_digit# => 4cusip.valid?# => truecusip.valid_format?# => truecusip.restore!# => '594918104'cusip.calculate_check_digit# => 4cusip.to_isin('US')# => #<SecId::ISIN>cusip.cins?# => true

SecId::SEDOL full example

# class levelSecId::SEDOL.valid?('B0Z52W5')# => trueSecId::SEDOL.valid_format?('B0Z52W')# => trueSecId::SEDOL.restore!('B0Z52W')# => 'B0Z52W5'SecId::SEDOL.check_digit('B0Z52W')# => 5# instance levelcusip=SecId::SEDOL.new('B0Z52W5')cusip.full_number# => 'B0Z52W5'cusip.check_digit# => 5cusip.valid?# => truecusip.valid_format?# => truecusip.restore!# => 'B0Z52W5'cusip.calculate_check_digit# => 5

SecId::FIGI full example

# class levelSecId::FIGI.valid?('BBG000DMBXR2')# => trueSecId::FIGI.valid_format?('BBG000DMBXR2')# => trueSecId::FIGI.restore!('BBG000DMBXR')# => 'BBG000DMBXR2'SecId::FIGI.check_digit('BBG000DMBXR')# => 2# instance levelfigi=SecId::FIGI.new('BBG000DMBXR2')figi.full_number# => 'BBG000DMBXR2'figi.prefix# => 'BB'figi.random_part# => '000DMBXR'figi.check_digit# => 2figi.valid?# => truefigi.valid_format?# => truefigi.restore!# => 'BBG000DMBXR2'figi.calculate_check_digit# => 2

SecId::CIK full example

# class levelSecId::CIK.valid?('0001094517')# => trueSecId::CIK.valid_format?('0001094517')# => trueSecId::CIK.restore!('1094517')# => '0001094517'SecId::CIK.check_digit('0001094517')# raises NotImplementedError# instance levelcik=SecId::CIK.new('0001094517')cik.full_number# => '0001094517'cik.padding# => '000'cik.identifier# => '1094517'cik.valid?# => truecik.valid_format?# => truecik.restore!# => '0001094517'cik.calculate_check_digit# raises NotImplementedErrorcik.check_digit# => nil

Development

After checking out the repo, runbin/setup to install dependencies.Then, runrake spec to run the tests. You can also runbin/consolefor an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, runbundle exec rake install.

Contributing

Bug reports and pull requests are welcome onGitHub athttps://github.com/svyatov/sec_id.

License

The gem is available as open source under the terms oftheMIT License.

About

Validate securities identification numbers (ISIN, CUSIP, SEDOL, FIGI, CIK) with ease!

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp