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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72c50ca8b151d2b24365161cf1349d638bfd71c5
4
- data.tar.gz: 1f1f3a6c8607ffda761083b46bf934646409bf53
3
+ metadata.gz: 2966f074a72f9e3b0937e0d66ee7738f735da794
4
+ data.tar.gz: efdb4c760ec5945b8a5e2a90c2f046eeb4c4a898
5
5
  SHA512:
6
- metadata.gz: 17e22d743cf8fb12c058820cfcea5dcb7aa16b484b848eef444ded844fe715b42b5cc75d35ac6964ec0e9241c80a8549dd191233fb8d7183293a14c4dac5337e
7
- data.tar.gz: 6ad951a7bf8c9a5a500fbd01f693455a5403f037b3839e192d06d84d663d5d23a7194f4a331db2ab395ce8e45ee10fa181078cab577abaa272672427f8daaeaa
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 MyModel < ActiveRecord::Base
66
- include SecurityIdentifiers::Validators
67
-
68
- validates :isin, isin: true
69
- validates :cusip, cusip: true
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
@@ -10,6 +10,8 @@ module SecurityIdentifiers
10
10
  raise InvalidFormat if match_data.nil?
11
11
 
12
12
  @identifier, @original_check_digit = match_data.captures
13
+
14
+ fix! if @original_check_digit.nil?
13
15
  end
14
16
 
15
17
  def check_digit
@@ -10,6 +10,8 @@ module SecurityIdentifiers
10
10
  raise InvalidFormat if match_data.nil?
11
11
 
12
12
  @identifier, @country_code, @nsin, @original_check_digit = match_data.captures
13
+
14
+ fix! if @original_check_digit.nil?
13
15
  end
14
16
 
15
17
  def check_digit
@@ -10,6 +10,8 @@ module SecurityIdentifiers
10
10
  raise InvalidFormat if match_data.nil?
11
11
 
12
12
  @identifier, @original_check_digit = match_data.captures
13
+
14
+ fix! if @original_check_digit.nil?
13
15
  end
14
16
 
15
17
  def check_digit
@@ -1,5 +1,5 @@
1
1
  module SecurityIdentifiers
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  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 'is invalid' do
13
- expect(cusip).to_not be_valid
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 'is invalid' do
17
- expect(isin).to_not be_valid
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 'is invalid' do
13
- expect(sedol).to_not be_valid
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: security_identifiers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Johnson