{"id":15509867,"url":"https://github.com/svyatov/sec_id","last_synced_at":"2026-02-05T20:13:50.135Z","repository":{"id":48447538,"uuid":"168942920","full_name":"svyatov/sec_id","owner":"svyatov","description":"Validate securities identification numbers (ISIN, CUSIP, SEDOL, FIGI, CIK) with ease!","archived":false,"fork":false,"pushed_at":"2024-09-24T12:54:08.000Z","size":48,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-24T22:51:23.356Z","etag":null,"topics":["cik","cusip","figi","iban","isin","ruby","ruby-gem","sedol","validation"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/svyatov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-03T12:29:17.000Z","updated_at":"2024-09-24T12:54:11.000Z","dependencies_parsed_at":"2024-07-09T19:28:46.788Z","dependency_job_id":null,"html_url":"https://github.com/svyatov/sec_id","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svyatov%2Fsec_id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svyatov%2Fsec_id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svyatov%2Fsec_id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svyatov%2Fsec_id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svyatov","download_url":"https://codeload.github.com/svyatov/sec_id/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242358926,"owners_count":20115100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cik","cusip","figi","iban","isin","ruby","ruby-gem","sedol","validation"],"created_at":"2024-10-02T09:44:35.304Z","updated_at":"2026-02-05T20:13:50.129Z","avatar_url":"https://github.com/svyatov.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SecId [![Gem Version](https://img.shields.io/gem/v/sec_id)](https://rubygems.org/gems/sec_id) [![Codecov](https://img.shields.io/codecov/c/github/svyatov/sec_id)](https://app.codecov.io/gh/svyatov/sec_id) [![CI](https://github.com/svyatov/sec_id/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/svyatov/sec_id/actions?query=workflow%3ACI)\n\n\u003e Validate securities identification numbers with ease!\n\n## Table of Contents\n\n- [Supported Ruby Versions](#supported-ruby-versions)\n- [Installation](#installation)\n- [Supported Standards and Usage](#supported-standards-and-usage)\n  - [ISIN](#isin) - International Securities Identification Number\n  - [CUSIP](#cusip) - Committee on Uniform Securities Identification Procedures\n  - [CEI](#cei) - CUSIP Entity Identifier\n  - [SEDOL](#sedol) - Stock Exchange Daily Official List\n  - [FIGI](#figi) - Financial Instrument Global Identifier\n  - [LEI](#lei) - Legal Entity Identifier\n  - [IBAN](#iban) - International Bank Account Number\n  - [CIK](#cik) - Central Index Key\n  - [OCC](#occ) - Options Clearing Corporation Symbol\n  - [WKN](#wkn) - Wertpapierkennnummer\n  - [Valoren](#valoren) - Swiss Security Number\n  - [CFI](#cfi) - Classification of Financial Instruments\n  - [FISN](#fisn) - Financial Instrument Short Name\n- [Development](#development)\n- [Contributing](#contributing)\n- [Changelog](#changelog)\n- [Versioning](#versioning)\n- [License](#license)\n\n## Supported Ruby Versions\n\nRuby 3.1+ is required.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'sec_id', '~\u003e 4.4'\n```\n\nAnd then execute:\n\n```bash\nbundle install\n```\n\nOr install it yourself:\n\n```bash\ngem install sec_id\n```\n\n## Supported Standards and Usage\n\nAll identifier classes provide `valid?` and `valid_format?` methods at both class and instance levels.\n\n**Check-digit based identifiers** (ISIN, CUSIP, CEI, SEDOL, FIGI, LEI, IBAN) also provide:\n- `restore!` - restores check-digit and returns the full number\n- `check_digit` / `calculate_check_digit` - calculates and returns the check-digit\n\n**Normalization based identifiers** (CIK, OCC, Valoren) provide instead:\n- `normalize!` - pads/formats the identifier to its standard form\n\n### ISIN\n\n\u003e [International Securities Identification Number](https://en.wikipedia.org/wiki/International_Securities_Identification_Number) - a 12-character alphanumeric code that uniquely identifies a security.\n\n```ruby\n# class level\nSecId::ISIN.valid?('US5949181045')       # =\u003e true\nSecId::ISIN.valid_format?('US594918104') # =\u003e true\nSecId::ISIN.restore!('US594918104')      # =\u003e 'US5949181045'\nSecId::ISIN.check_digit('US594918104')   # =\u003e 5\n\n# instance level\nisin = SecId::ISIN.new('US5949181045')\nisin.full_number           # =\u003e 'US5949181045'\nisin.country_code          # =\u003e 'US'\nisin.nsin                  # =\u003e '594918104'\nisin.check_digit           # =\u003e 5\nisin.valid?                # =\u003e true\nisin.valid_format?         # =\u003e true\nisin.restore!              # =\u003e 'US5949181045'\nisin.calculate_check_digit # =\u003e 5\nisin.to_cusip              # =\u003e #\u003cSecId::CUSIP\u003e\nisin.nsin_type             # =\u003e :cusip\nisin.to_nsin               # =\u003e #\u003cSecId::CUSIP\u003e\n\n# NSIN extraction for different countries\nSecId::ISIN.new('GB00B02H2F76').nsin_type  # =\u003e :sedol\nSecId::ISIN.new('GB00B02H2F76').to_nsin    # =\u003e #\u003cSecId::SEDOL\u003e\nSecId::ISIN.new('DE0007164600').nsin_type  # =\u003e :wkn\nSecId::ISIN.new('DE0007164600').to_nsin    # =\u003e #\u003cSecId::WKN\u003e\nSecId::ISIN.new('CH0012221716').nsin_type  # =\u003e :valoren\nSecId::ISIN.new('CH0012221716').to_nsin    # =\u003e #\u003cSecId::Valoren\u003e\nSecId::ISIN.new('FR0000120271').nsin_type  # =\u003e :generic\nSecId::ISIN.new('FR0000120271').to_nsin    # =\u003e '000012027' (raw NSIN string)\n\n# Type-specific conversion methods with validation\nSecId::ISIN.new('GB00B02H2F76').sedol?     # =\u003e true\nSecId::ISIN.new('GB00B02H2F76').to_sedol   # =\u003e #\u003cSecId::SEDOL\u003e\nSecId::ISIN.new('DE0007164600').wkn?       # =\u003e true\nSecId::ISIN.new('DE0007164600').to_wkn     # =\u003e #\u003cSecId::WKN\u003e\nSecId::ISIN.new('CH0012221716').valoren?   # =\u003e true\nSecId::ISIN.new('CH0012221716').to_valoren # =\u003e #\u003cSecId::Valoren\u003e\n```\n\n### CUSIP\n\n\u003e [Committee on Uniform Securities Identification Procedures](https://en.wikipedia.org/wiki/CUSIP) - a 9-character alphanumeric code that identifies North American securities.\n\n```ruby\n# class level\nSecId::CUSIP.valid?('594918104')       # =\u003e true\nSecId::CUSIP.valid_format?('59491810') # =\u003e true\nSecId::CUSIP.restore!('59491810')      # =\u003e '594918104'\nSecId::CUSIP.check_digit('59491810')   # =\u003e 4\n\n# instance level\ncusip = SecId::CUSIP.new('594918104')\ncusip.full_number           # =\u003e '594918104'\ncusip.cusip6                # =\u003e '594918'\ncusip.issue                 # =\u003e '10'\ncusip.check_digit           # =\u003e 4\ncusip.valid?                # =\u003e true\ncusip.valid_format?         # =\u003e true\ncusip.restore!              # =\u003e '594918104'\ncusip.calculate_check_digit # =\u003e 4\ncusip.to_isin('US')         # =\u003e #\u003cSecId::ISIN\u003e\ncusip.cins?                 # =\u003e false\n```\n\n### CEI\n\n\u003e [CUSIP Entity Identifier](https://www.cusip.com/identifiers.html) - a 10-character alphanumeric code that identifies legal entities in the syndicated loan market.\n\n```ruby\n# class level\nSecId::CEI.valid?('A0BCDEFGH1')       # =\u003e true\nSecId::CEI.valid_format?('A0BCDEFGH') # =\u003e true\nSecId::CEI.restore!('A0BCDEFGH')      # =\u003e 'A0BCDEFGH1'\nSecId::CEI.check_digit('A0BCDEFGH')   # =\u003e 1\n\n# instance level\ncei = SecId::CEI.new('A0BCDEFGH1')\ncei.full_number           # =\u003e 'A0BCDEFGH1'\ncei.prefix                # =\u003e 'A'\ncei.numeric               # =\u003e '0'\ncei.entity_id             # =\u003e 'BCDEFGH'\ncei.check_digit           # =\u003e 1\ncei.valid?                # =\u003e true\ncei.valid_format?         # =\u003e true\ncei.restore!              # =\u003e 'A0BCDEFGH1'\ncei.calculate_check_digit # =\u003e 1\n```\n\n### SEDOL\n\n\u003e [Stock Exchange Daily Official List](https://en.wikipedia.org/wiki/SEDOL) - a 7-character alphanumeric code used in the United Kingdom, Ireland, Crown Dependencies (Jersey, Guernsey, Isle of Man), and select British Overseas Territories.\n\n```ruby\n# class level\nSecId::SEDOL.valid?('B0Z52W5')       # =\u003e true\nSecId::SEDOL.valid_format?('B0Z52W') # =\u003e true\nSecId::SEDOL.restore!('B0Z52W')      # =\u003e 'B0Z52W5'\nSecId::SEDOL.check_digit('B0Z52W')   # =\u003e 5\n\n# instance level\nsedol = SecId::SEDOL.new('B0Z52W5')\nsedol.full_number           # =\u003e 'B0Z52W5'\nsedol.check_digit           # =\u003e 5\nsedol.valid?                # =\u003e true\nsedol.valid_format?         # =\u003e true\nsedol.restore!              # =\u003e 'B0Z52W5'\nsedol.calculate_check_digit # =\u003e 5\nsedol.to_isin               # =\u003e #\u003cSecId::ISIN\u003e (GB ISIN by default)\nsedol.to_isin('IE')         # =\u003e #\u003cSecId::ISIN\u003e (IE ISIN)\n```\n\n### FIGI\n\n\u003e [Financial Instrument Global Identifier](https://en.wikipedia.org/wiki/Financial_Instrument_Global_Identifier) - a 12-character alphanumeric code that provides unique identification of financial instruments.\n\n```ruby\n# class level\nSecId::FIGI.valid?('BBG000DMBXR2')        # =\u003e true\nSecId::FIGI.valid_format?('BBG000DMBXR2') # =\u003e true\nSecId::FIGI.restore!('BBG000DMBXR')       # =\u003e 'BBG000DMBXR2'\nSecId::FIGI.check_digit('BBG000DMBXR')    # =\u003e 2\n\n# instance level\nfigi = SecId::FIGI.new('BBG000DMBXR2')\nfigi.full_number           # =\u003e 'BBG000DMBXR2'\nfigi.prefix                # =\u003e 'BB'\nfigi.random_part           # =\u003e '000DMBXR'\nfigi.check_digit           # =\u003e 2\nfigi.valid?                # =\u003e true\nfigi.valid_format?         # =\u003e true\nfigi.restore!              # =\u003e 'BBG000DMBXR2'\nfigi.calculate_check_digit # =\u003e 2\n```\n\n### LEI\n\n\u003e [Legal Entity Identifier](https://en.wikipedia.org/wiki/Legal_Entity_Identifier) - a 20-character alphanumeric code that uniquely identifies legal entities participating in financial transactions.\n\n```ruby\n# class level\nSecId::LEI.valid?('5493006MHB84DD0ZWV18')       # =\u003e true\nSecId::LEI.valid_format?('5493006MHB84DD0ZWV')  # =\u003e true\nSecId::LEI.restore!('5493006MHB84DD0ZWV')       # =\u003e '5493006MHB84DD0ZWV18'\nSecId::LEI.check_digit('5493006MHB84DD0ZWV')    # =\u003e 18\n\n# instance level\nlei = SecId::LEI.new('5493006MHB84DD0ZWV18')\nlei.full_number           # =\u003e '5493006MHB84DD0ZWV18'\nlei.lou_id                # =\u003e '5493'\nlei.reserved              # =\u003e '00'\nlei.entity_id             # =\u003e '6MHB84DD0ZWV'\nlei.check_digit           # =\u003e 18\nlei.valid?                # =\u003e true\nlei.valid_format?         # =\u003e true\nlei.restore!              # =\u003e '5493006MHB84DD0ZWV18'\nlei.calculate_check_digit # =\u003e 18\n```\n\n### IBAN\n\n\u003e [International Bank Account Number](https://en.wikipedia.org/wiki/International_Bank_Account_Number) - an internationally standardized system for identifying bank accounts across national borders (ISO 13616).\n\n```ruby\n# class level\nSecId::IBAN.valid?('DE89370400440532013000')       # =\u003e true\nSecId::IBAN.valid_format?('DE370400440532013000')  # =\u003e true\nSecId::IBAN.restore!('DE370400440532013000')       # =\u003e 'DE89370400440532013000'\nSecId::IBAN.check_digit('DE370400440532013000')    # =\u003e 89\n\n# instance level\niban = SecId::IBAN.new('DE89370400440532013000')\niban.full_number           # =\u003e 'DE89370400440532013000'\niban.country_code          # =\u003e 'DE'\niban.bban                  # =\u003e '370400440532013000'\niban.bank_code             # =\u003e '37040044'\niban.account_number        # =\u003e '0532013000'\niban.check_digit           # =\u003e 89\niban.valid?                # =\u003e true\niban.valid_format?         # =\u003e true\niban.restore!              # =\u003e 'DE89370400440532013000'\niban.calculate_check_digit # =\u003e 89\niban.known_country?        # =\u003e true\n```\n\nFull BBAN structural validation is supported for EU/EEA countries. Other countries have length-only validation.\n\n### CIK\n\n\u003e [Central Index Key](https://en.wikipedia.org/wiki/Central_Index_Key) - a 10-digit number used by the SEC to identify corporations and individuals who have filed disclosures.\n\n```ruby\n# class level\nSecId::CIK.valid?('0001094517')        # =\u003e true\nSecId::CIK.valid_format?('0001094517') # =\u003e true\nSecId::CIK.normalize!('1094517')       # =\u003e '0001094517'\n\n# instance level\ncik = SecId::CIK.new('0001094517')\ncik.full_number   # =\u003e '0001094517'\ncik.padding       # =\u003e '000'\ncik.identifier    # =\u003e '1094517'\ncik.valid?        # =\u003e true\ncik.valid_format? # =\u003e true\ncik.normalize!    # =\u003e '0001094517'\ncik.to_s          # =\u003e '0001094517'\n```\n\n### OCC\n\n\u003e [Options Clearing Corporation Symbol](https://en.wikipedia.org/wiki/Option_symbol#The_OCC_Option_Symbol) - a 21-character code used to identify equity options contracts.\n\n```ruby\n# class level\nSecId::OCC.valid?('BRKB  100417C00090000')        # =\u003e true\nSecId::OCC.valid_format?('BRKB  100417C00090000') # =\u003e true\nSecId::OCC.normalize!('BRKB100417C00090000')      # =\u003e 'BRKB  100417C00090000'\nSecId::OCC.build(\n  underlying: 'BRKB',\n  date: Date.new(2010, 4, 17),\n  type: 'C',\n  strike: 90,\n)                                                 # =\u003e #\u003cSecId::OCC\u003e\n\n# instance level\nocc = SecId::OCC.new('BRKB  100417C00090000')\nocc.full_symbol   # =\u003e 'BRKB  100417C00090000'\nocc.underlying    # =\u003e 'BRKB'\nocc.date_str      # =\u003e '100417'\nocc.date_obj      # =\u003e #\u003cDate: 2010-04-17\u003e\nocc.type          # =\u003e 'C'\nocc.strike        # =\u003e 90.0\nocc.valid?        # =\u003e true\nocc.valid_format? # =\u003e true\nocc.normalize!    # =\u003e 'BRKB  100417C00090000'\n\nocc = SecId::OCC.new('BRKB 2010-04-17C00090000')\nocc.valid_format? # =\u003e false\nocc.normalize!    # raises SecId::InvalidFormatError\n\nocc = SecId::OCC.new('X 250620C00050000')\nocc.full_symbol   # =\u003e 'X 250620C00050000'\nocc.valid?        # =\u003e true\nocc.normalize!    # =\u003e 'X     250620C00050000'\nocc.full_symbol   # =\u003e 'X     250620C00050000'\n```\n\n### WKN\n\n\u003e [Wertpapierkennnummer](https://en.wikipedia.org/wiki/Wertpapierkennnummer) - a 6-character alphanumeric code used to identify securities in Germany.\n\n```ruby\n# class level\nSecId::WKN.valid?('514000')        # =\u003e true\nSecId::WKN.valid?('CBK100')        # =\u003e true\nSecId::WKN.valid_format?('514000') # =\u003e true\n\n# instance level\nwkn = SecId::WKN.new('514000')\nwkn.full_number   # =\u003e '514000'\nwkn.identifier    # =\u003e '514000'\nwkn.valid?        # =\u003e true\nwkn.valid_format? # =\u003e true\nwkn.to_s          # =\u003e '514000'\nwkn.to_isin       # =\u003e #\u003cSecId::ISIN\u003e (DE ISIN)\n```\n\nWKN excludes letters I and O to avoid confusion with digits 1 and 0.\n\n### Valoren\n\n\u003e [Valoren](https://en.wikipedia.org/wiki/Valoren_number) - a numeric identifier for securities in Switzerland, Liechtenstein, and Belgium.\n\n```ruby\n# class level\nSecId::Valoren.valid?('3886335')        # =\u003e true\nSecId::Valoren.valid?('24476758')       # =\u003e true\nSecId::Valoren.valid?('35514757')       # =\u003e true\nSecId::Valoren.valid?('97429325')       # =\u003e true\nSecId::Valoren.valid_format?('3886335') # =\u003e true\nSecId::Valoren.normalize!('3886335')    # =\u003e '003886335'\n\n# instance level\nvaloren = SecId::Valoren.new('3886335')\nvaloren.full_number   # =\u003e '3886335'\nvaloren.padding       # =\u003e ''\nvaloren.identifier    # =\u003e '3886335'\nvaloren.valid?        # =\u003e true\nvaloren.valid_format? # =\u003e true\nvaloren.normalize!    # =\u003e '003886335'\nvaloren.to_s          # =\u003e '003886335'\nvaloren.to_isin       # =\u003e #\u003cSecId::ISIN\u003e (CH ISIN by default)\nvaloren.to_isin('LI') # =\u003e #\u003cSecId::ISIN\u003e (LI ISIN)\n```\n\n### CFI\n\n\u003e [Classification of Financial Instruments](https://en.wikipedia.org/wiki/ISO_10962) - a 6-character alphabetic code that classifies financial instruments per ISO 10962.\n\n```ruby\n# class level\nSecId::CFI.valid?('ESXXXX')        # =\u003e true\nSecId::CFI.valid?('ESVUFR')        # =\u003e true\nSecId::CFI.valid_format?('ESXXXX') # =\u003e true\n\n# instance level\ncfi = SecId::CFI.new('ESVUFR')\ncfi.full_number    # =\u003e 'ESVUFR'\ncfi.identifier     # =\u003e 'ESVUFR'\ncfi.category_code  # =\u003e 'E'\ncfi.group_code     # =\u003e 'S'\ncfi.category       # =\u003e :equity\ncfi.group          # =\u003e :common_shares\ncfi.valid?         # =\u003e true\ncfi.valid_format?  # =\u003e true\n\n# Equity-specific predicates\ncfi.equity?        # =\u003e true\ncfi.voting?        # =\u003e true\ncfi.restrictions?  # =\u003e false\ncfi.fully_paid?    # =\u003e true\ncfi.registered?    # =\u003e true\n```\n\nCFI validates the category code (position 1) against 14 valid values and the group code (position 2) against valid values for that category. Attribute positions 3-6 accept any letter A-Z, with X meaning \"not applicable\".\n\n### FISN\n\n\u003e [Financial Instrument Short Name](https://en.wikipedia.org/wiki/ISO_18774) - a human-readable short name for financial instruments per ISO 18774.\n\n```ruby\n# class level\nSecId::FISN.valid?('APPLE INC/SH')        # =\u003e true\nSecId::FISN.valid?('apple inc/sh')        # =\u003e true (normalized to uppercase)\nSecId::FISN.valid_format?('APPLE INC/SH') # =\u003e true\n\n# instance level\nfisn = SecId::FISN.new('APPLE INC/SH')\nfisn.full_number   # =\u003e 'APPLE INC/SH'\nfisn.identifier    # =\u003e 'APPLE INC/SH'\nfisn.issuer        # =\u003e 'APPLE INC'\nfisn.description   # =\u003e 'SH'\nfisn.valid?        # =\u003e true\nfisn.valid_format? # =\u003e true\nfisn.to_s          # =\u003e 'APPLE INC/SH'\n```\n\nFISN format: `Issuer Name/Abbreviated Instrument Description` with issuer (1-15 chars) and description (1-19 chars) separated by a forward slash. Character set: uppercase A-Z, digits 0-9, and space.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies.\nThen, run `bundle exec rake` to run the tests. You can also run `bin/console`\nfor an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Make your changes and run tests (`bundle exec rake`)\n4. Commit using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format (`git commit -m 'feat: add some feature'`)\n5. Push to the branch (`git push origin my-new-feature`)\n6. Create a new Pull Request\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes, following [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format.\n\n## Versioning\n\nThis project follows [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html)\n\n## License\n\nThe gem is available as open source under the terms of\nthe [MIT License](LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvyatov%2Fsec_id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvyatov%2Fsec_id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvyatov%2Fsec_id/lists"}