security_identifiers 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -11
- data/lib/security_identifiers/base.rb +4 -4
- data/lib/security_identifiers/cusip.rb +2 -0
- data/lib/security_identifiers/isin.rb +2 -0
- data/lib/security_identifiers/sedol.rb +2 -0
- data/lib/security_identifiers/version.rb +1 -1
- data/spec/cusip_spec.rb +2 -10
- data/spec/isin_spec.rb +2 -10
- data/spec/sedol_spec.rb +2 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2966f074a72f9e3b0937e0d66ee7738f735da794
|
4
|
+
data.tar.gz: efdb4c760ec5945b8a5e2a90c2f046eeb4c4a898
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e2c726c65b626c4cbb6f6d992b013a8c2280ee6ae3f7a30da5731951b56f0890684eef22f938d1e6b3218513c383108010cb81a8d3b826f2871198be3dbc2df
|
7
|
+
data.tar.gz: 0ec8c45c8a1a9665e4f3293e55e4125b81779b25e2f3e353b8c6d9f35e0d11272a609b2e8084990ff6a7a48db3034fe24f57a2d549cb49ed39361982fae8a122
|
data/README.md
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/invisiblelines/security_identifiers.png?branch=master)](https://travis-ci.org/invisiblelines/security_identifiers)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/invisiblelines/security_identifiers.png)](https://codeclimate.com/github/invisiblelines/security_identifiers)
|
5
5
|
[![Dependency Status](https://gemnasium.com/invisiblelines/security_identifiers.png)](https://gemnasium.com/invisiblelines/security_identifiers)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/security_identifiers.svg)](http://badge.fury.io/rb/security_identifiers)
|
6
7
|
|
7
|
-
Security identifiers validation library for Ruby.
|
8
|
+
Security identifiers validation library for Ruby.
|
8
9
|
|
9
10
|
Currently supports
|
10
11
|
|
@@ -42,11 +43,6 @@ or with an invalid identifier
|
|
42
43
|
|
43
44
|
isin = SecurityIdentifiers::ISIN.new('S0378331005') # => raises SecurityIdentifiers::InvalidFormat
|
44
45
|
|
45
|
-
To fix a missing check digit
|
46
|
-
|
47
|
-
isin = SecurityIdentifiers::ISIN.new('US037833100')
|
48
|
-
isin.fix!
|
49
|
-
|
50
46
|
Now you can validate
|
51
47
|
|
52
48
|
isin.valid? # => true
|
@@ -62,13 +58,24 @@ CUSIPs and SEDOLs also support converting these identifiers to ISINs.
|
|
62
58
|
|
63
59
|
Includes custom validators for use in ActiveModel/ActiveRecord
|
64
60
|
|
65
|
-
class
|
66
|
-
include
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
class Security
|
62
|
+
include ActiveModel::Validations
|
63
|
+
include SecurityIdentifiers::Validations
|
64
|
+
|
65
|
+
attr_accessor :cusip, :isin, :sedol
|
66
|
+
|
67
|
+
def initialize(options = {})
|
68
|
+
@cusip = options[:cusip]
|
69
|
+
@isin = options[:isin]
|
70
|
+
@sedol = options[:sedol]
|
71
|
+
end
|
72
|
+
|
73
|
+
validates :cusip, cusip: true, allow_blank: true
|
74
|
+
validates :isin, isin: true, allow_blank: true
|
75
|
+
validates :sedol, sedol: true, allow_blank: true
|
70
76
|
end
|
71
77
|
|
78
|
+
|
72
79
|
## Contributing
|
73
80
|
|
74
81
|
1. Fork it
|
@@ -15,10 +15,6 @@ module SecurityIdentifiers
|
|
15
15
|
"#{@identifier}#{check_digit}"
|
16
16
|
end
|
17
17
|
|
18
|
-
def fix!
|
19
|
-
@original_check_digit = check_digit
|
20
|
-
end
|
21
|
-
|
22
18
|
private
|
23
19
|
|
24
20
|
def digits
|
@@ -33,6 +29,10 @@ module SecurityIdentifiers
|
|
33
29
|
@odd_values ||= digits.values_at(* digits.each_index.select { |i| i.odd? })
|
34
30
|
end
|
35
31
|
|
32
|
+
def fix!
|
33
|
+
@original_check_digit = check_digit
|
34
|
+
end
|
35
|
+
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
data/spec/cusip_spec.rb
CHANGED
@@ -9,8 +9,8 @@ describe CUSIP do
|
|
9
9
|
context 'Without a check digit' do
|
10
10
|
let(:cusip) { CUSIP.new('83764912') }
|
11
11
|
|
12
|
-
it '
|
13
|
-
expect(cusip).to_not
|
12
|
+
it 'calculates the check digit' do
|
13
|
+
expect(cusip.original_check_digit).to_not be_nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -70,12 +70,4 @@ describe CUSIP do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context '#fix!' do
|
74
|
-
let(:cusip) { CUSIP.new('125509BG') }
|
75
|
-
|
76
|
-
it 'calculates the check digit' do
|
77
|
-
expect { cusip.fix! }.to change(cusip, :original_check_digit).from(nil).to(3)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
73
|
end
|
data/spec/isin_spec.rb
CHANGED
@@ -13,8 +13,8 @@ describe ISIN do
|
|
13
13
|
context 'Without a check digit' do
|
14
14
|
let(:isin) { ISIN.new('US037833100') }
|
15
15
|
|
16
|
-
it '
|
17
|
-
expect(isin).
|
16
|
+
it 'calculates the check digit' do
|
17
|
+
expect(isin.original_check_digit).not_to be_nil
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -58,12 +58,4 @@ describe ISIN do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context '#fix!' do
|
62
|
-
let(:isin) { ISIN.new('AU0000XVGZA') }
|
63
|
-
|
64
|
-
it 'calculates the check digit' do
|
65
|
-
expect { isin.fix! }.to change(isin, :original_check_digit).from(nil).to(3)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
61
|
end
|
data/spec/sedol_spec.rb
CHANGED
@@ -9,8 +9,8 @@ describe SEDOL do
|
|
9
9
|
context 'Without a check digit' do
|
10
10
|
let(:sedol) { SEDOL.new('B0WNLY') }
|
11
11
|
|
12
|
-
it '
|
13
|
-
expect(sedol).to_not
|
12
|
+
it 'calculates the check digit' do
|
13
|
+
expect(sedol.original_check_digit).to_not be_nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -50,12 +50,4 @@ describe SEDOL do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context '#fix!' do
|
54
|
-
let(:sedol) { SEDOL.new('B0WNLY') }
|
55
|
-
|
56
|
-
it 'calculates the check digit' do
|
57
|
-
expect { sedol.fix! }.to change(sedol, :original_check_digit).from(nil).to(7)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
53
|
end
|