Skip to content

Commit

Permalink
Add CINS check method (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtn authored Sep 23, 2024
1 parent bc69332 commit e4d7d2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/sec_id/cusip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def to_isin(country_code)
isin
end

# CUSIP International Numbering System
def cins?
!cusip6[0].match?(/[0-9]/)
end

private

# https://en.wikipedia.org/wiki/Luhn_algorithm
Expand Down
18 changes: 18 additions & 0 deletions spec/sec_id/cusip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@
end
end

describe '#cins?' do
context 'when a CINS' do
let(:cusip_number) { 'G0052B105' }

it 'returns true' do
expect(cusip.cins?).to be(true)
end
end

context 'when not a CINS' do
let(:cusip_number) { '084664BL4' }

it 'returns false' do
expect(cusip.cins?).to be(false)
end
end
end

describe '.restore!' do
context 'when CUSIP is incorrect' do
it 'raises an error' do
Expand Down

0 comments on commit e4d7d2a

Please sign in to comment.