ibandit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36930d16f5443cccf34293a0cb6014b8dc33c337
4
+ data.tar.gz: e8201ef2d1053ed3293ac3d620e0cd494e1f66a6
5
+ SHA512:
6
+ metadata.gz: 98a90bb5ed4f7b50bf82abed4709bf919d7fad46f7695dc40e317d16c102aef3b097ef928806b0d3393a07e4d2701981727cf2c77b90427b41f485e449d5f437
7
+ data.tar.gz: 7c02243b084a98aac05bd911bf527667b47cf98a362795fb6f7214018f563ce8ad3726f623201a34c3e6cd883b697c8531a3c08632b7f505446b908066a55a18
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ .bundle
3
+ *.gem
4
+ .DS_Store
@@ -0,0 +1,43 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Include:
5
+ - config.ru
6
+ - Rakefile
7
+ Exclude:
8
+ - .*/**/*
9
+
10
+ # Limit lines to 80 characters.
11
+ LineLength:
12
+ Max: 80
13
+
14
+ ClassLength:
15
+ Max: 150
16
+
17
+ # Avoid single-line methods.
18
+ SingleLineMethods:
19
+ AllowIfMethodIsEmpty: true
20
+
21
+ # Wants underscores in all large numbers. Pain in the ass for things like
22
+ # unix timestamps.
23
+ NumericLiterals:
24
+ Enabled: false
25
+
26
+ # Wants you to use the same argument names for every reduce. This seems kinda
27
+ # naff compared to naming them semantically
28
+ SingleLineBlockParams:
29
+ Enabled: false
30
+
31
+ Style/SignalException:
32
+ EnforcedStyle: 'only_raise'
33
+
34
+ # Wants to exclude accents from comments
35
+ Style/AsciiComments:
36
+ Enabled: false
37
+
38
+ # Configuration parameters: CountComments.
39
+ Metrics/MethodLength:
40
+ Max: 25
41
+
42
+ Style/DotPosition:
43
+ EnforcedStyle: 'trailing'
@@ -0,0 +1,23 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-12-08 13:56:37 +0000 using RuboCop version 0.27.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 4
9
+ Metrics/AbcSize:
10
+ Max: 28
11
+
12
+ # Offense count: 1
13
+ # Configuration parameters: CountComments.
14
+ Metrics/ClassLength:
15
+ Max: 110
16
+
17
+ # Offense count: 1
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 10
20
+
21
+ # Offense count: 4
22
+ Style/Documentation:
23
+ Enabled: false
@@ -0,0 +1,48 @@
1
+ ## 0.1.0 - December 29, 2014
2
+
3
+ - Initial public release
4
+
5
+ ## 0.0.16 - December 29, 2014
6
+
7
+ - Fix error handling in Modulus 97-10 check digit calculation
8
+
9
+ ## 0.0.15 - December 26, 2014
10
+
11
+ - Raise namespaced errors
12
+
13
+ ## 0.0.14 - December 17, 2014
14
+
15
+ - Add the Netherlands to IBANBuilder, and rename CheckDigit.mod_11
16
+
17
+ ## 0.0.13 - December 17, 2014
18
+
19
+ - Send cleaned (de-space/hyphenated) sort codes to the BIC finder lambda
20
+
21
+ ## 0.0.12 - December 16, 2014
22
+
23
+ - Allow spaced as well as hyphenated UK sort codes
24
+
25
+ ## 0.0.11 - December 15, 2014
26
+
27
+ - `IBAN#to_s` returns IBAN string rather than object properties
28
+ - Local check digits accessors
29
+ - Only raises `ArgumentError`
30
+ - Additional documentation on local details/IBAN conversion quirks
31
+
32
+ ## 0.0.10 - December 13, 2014
33
+
34
+ - Update format validations for all IBAN countries. Add local_check_digits
35
+ accessor method to IBAN.
36
+
37
+ ## 0.0.5 - December 8, 2014
38
+
39
+ - Add IBANSTRUCTURE file. All IBAN countries are now supported for validation
40
+ and deconstruction.
41
+
42
+ ## 0.0.2 - December 4, 2014
43
+
44
+ - Rename to ibandit
45
+
46
+ ## 0.0.1 - November 27, 2014
47
+
48
+ - Initial commit
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 GoCardless
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,303 @@
1
+ # Ibandit
2
+
3
+ Ibandit is a Ruby library for manipulating and validating
4
+ [IBANs](http://en.wikipedia.org/wiki/International_Bank_Account_Number). It
5
+ allows you to:
6
+
7
+ 1. Create an IBAN from national banking details
8
+ 2. Deconstruct an IBAN into national banking details
9
+ 3. Validate an IBAN's check digits and structure
10
+
11
+ Ibandit also provides helper methods for validating some countries' local
12
+ account details.
13
+
14
+ The gem is kept up to date using the IBAN structure file from SWIFT.
15
+
16
+ ## Usage
17
+
18
+ ### Installation
19
+
20
+ You don't need this source code unless you want to modify the gem. If you just
21
+ want to use it, you should run:
22
+
23
+ ```ruby
24
+ gem install ibandit
25
+ ```
26
+
27
+ ### Creating IBANs
28
+
29
+ All functionality is based around `IBAN` objects. To create one, simply pass a
30
+ string to `Ibandit::IBAN.new`. Note that you don't need to worry about case and
31
+ whitespace:
32
+
33
+ ```ruby
34
+ iban = Ibandit::IBAN.new("xq75 B a dCode 666")
35
+ iban.to_s # => "XQ75BADCODE666"
36
+ iban.to_s(:formatted) # => "XQ75 BADC ODE6 66"
37
+ ```
38
+
39
+ ### Validating an IBAN
40
+
41
+ IBANs are validated based on their structure and check-digits:
42
+
43
+ ```ruby
44
+ iban = Ibandit::IBAN.new("XQ75 BADCODE 666")
45
+
46
+ iban.valid? # => false
47
+ ```
48
+
49
+ After validations, you can fetch details of any errors:
50
+
51
+ ```ruby
52
+ iban.errors # => { country_code: "'XQ' is not a valid..." }
53
+ ```
54
+
55
+ The following error keys may be set:
56
+ - `country_code`
57
+ - `check_digits`
58
+ - `characters`
59
+ - `length`
60
+ - `format`
61
+
62
+ ### Deconstructing an IBAN into national banking details
63
+
64
+ SWIFT define the following components for IBANs, and publish details of how each
65
+ county combines them:
66
+
67
+ `country_code`
68
+ : The [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) country code prefix
69
+
70
+ `check_digits`
71
+ : Two digits calculated using part of the ISO/IEC 7064:2003 standard
72
+
73
+ `bank_code`
74
+ : The SWIFT identifier for the bank to which the IBAN refers
75
+
76
+ `branch_code`
77
+ : The SWIFT identifer for the branch to which the IBAN refers (not used in all countries)
78
+
79
+ `account_number`
80
+ : The account number for the account
81
+
82
+ `iban_national_id`
83
+ : The national ID for the bank / branch as documented by SWIFT
84
+
85
+ The SWIFT IBAN components are all available as methods on an `IBAN` object:
86
+
87
+ ```ruby
88
+ iban = Ibandit::IBAN.new("GB82 WEST 1234 5698 7654 32")
89
+
90
+ iban.country_code # => "GB"
91
+ iban.check_digits # => "82"
92
+ iban.bank_code # => "WEST"
93
+ iban.branch_code # => "123456"
94
+ iban.account_number # => "98765432"
95
+ iban.iban_national_id # => "WEST123456"
96
+ ```
97
+
98
+ In addition, it is often useful to extract any local check digits from the IBAN.
99
+ These are available through a `local_check_digits` method:
100
+
101
+ ```ruby
102
+ iban = Ibandit::IBAN.new("ES12 1234 5678 9112 3456 7890")
103
+
104
+ iban.local_check_digits # => "91"
105
+ ```
106
+
107
+ ### Initializing Ibandit
108
+
109
+ The UK and Ireland both use part of the BIC as the `bank_code` in their IBANs.
110
+ If you wish to construct UK or Irish IBANs you will either need to pass the
111
+ `bank_code` explicitly, or configure Ibandit with a BIC finder:
112
+
113
+ ```ruby
114
+ # config/initializers/ibandit.rb
115
+ Ibandit.bic_finder = -> (country_code, national_id) do
116
+ # This assumes you have `BankDirectoryPlus` set up to access the data provided
117
+ # by SWIFTRef in their Bank Directory Plus product. The `national_id` is the
118
+ # local national ID, not the "IBAN National ID" referred to in the IBAN Plus
119
+ # file (since that is the `bank_code` and the `branch_code`).
120
+ BankDirectoryPlus.find_by(country_code: country_code,
121
+ national_id: national_id).
122
+ try(:bic)
123
+ end
124
+ ```
125
+
126
+ ### Creating an IBAN from national banking details
127
+
128
+ In many countries customers are familiar with national details rather than
129
+ their IBAN. For example, in the UK customers use their Account Number and Sort
130
+ Code.
131
+
132
+ To build an IBAN from local details:
133
+
134
+ ```ruby
135
+ # Austria
136
+ iban = Ibandit::IBANBuilder.build(
137
+ country_code: 'AT',
138
+ account_number: '234573201',
139
+ bank_code: '19043'
140
+ )
141
+ iban.iban # => "AT611904300234573201"
142
+
143
+ # Belgium
144
+ iban = Ibandit::IBANBuilder.build(
145
+ country_code: 'BE',
146
+ account_number: '510-0075470-61'
147
+ )
148
+ iban.iban # => "BE62510007547061"
149
+
150
+ # Cyprus
151
+ iban = Ibandit::IBANBuilder.build(
152
+ country_code: 'CY',
153
+ account_number: '1200527600',
154
+ bank_code: '002',
155
+ branch_code: '00128'
156
+ )
157
+ iban.iban # => "CY17002001280000001200527600"
158
+
159
+ # Germany
160
+ iban = Ibandit::IBANBuilder.build(
161
+ country_code: 'DE',
162
+ bank_code: '37040044',
163
+ account_number: '0532013000'
164
+ )
165
+ iban.iban # => "DE89370400440532013000"
166
+
167
+ # Estonia
168
+ iban = Ibandit::IBANBuilder.build(
169
+ country_code: 'EE',
170
+ account_number: '111020145685'
171
+ )
172
+ iban.iban # => "EE412200111020145685"
173
+
174
+ # Finland
175
+ iban = Ibandit::IBANBuilder.build(
176
+ country_code: 'FI',
177
+ bank_code: '123456'
178
+ account_number: '785'
179
+ )
180
+ iban.iban # => "FI2112345600000785"
181
+
182
+ # France
183
+ iban = Ibandit::IBANBuilder.build(
184
+ country_code: 'FR',
185
+ bank_code: '20041',
186
+ branch_code: '01005',
187
+ account_number: '0500013M02606',
188
+ )
189
+ iban.iban # => "FR1420041010050500013M02606"
190
+
191
+ # United Kingdom
192
+ iban = Ibandit::IBANBuilder.build(
193
+ country_code: 'GB',
194
+ bank_code: 'BARC', # optional if a BIC finder is configured
195
+ branch_code: '200000',
196
+ account_number: '55779911'
197
+ )
198
+ iban.iban # => "GB60BARC20000055779911"
199
+
200
+ # Ireland
201
+ iban = Ibandit::IBANBuilder.build(
202
+ country_code: 'IE',
203
+ bank_code: 'AIBK', # optional if a BIC finder is configured
204
+ branch_code: '931152',
205
+ account_number: '12345678'
206
+ )
207
+ iban.iban # => "IE29AIBK93115212345678"
208
+
209
+ # Italy
210
+ iban = Ibandit::IBANBuilder.build(
211
+ country_code: 'IT',
212
+ bank_code: '05428',
213
+ branch_code: '11101',
214
+ account_number: '000000123456'
215
+ )
216
+ iban.iban # => "IT60X0542811101000000123456"
217
+
218
+ # Latvia
219
+ iban = Ibandit::IBANBuilder.build(
220
+ country_code: 'LV',
221
+ account_number: '1234567890123',
222
+ bank_code: 'BANK'
223
+ )
224
+ iban.iban # => "LV72BANK1234567890123"
225
+
226
+ # Luxembourg
227
+ iban = Ibandit::IBANBuilder.build(
228
+ country_code: 'LU',
229
+ account_number: '1234567890123',
230
+ bank_code: 'BANK'
231
+ )
232
+ iban.iban # => "LU75BANK1234567890123"
233
+
234
+ # Monaco
235
+ iban = Ibandit::IBANBuilder.build(
236
+ country_code: 'MC',
237
+ bank_code: '20041',
238
+ branch_code: '01005',
239
+ account_number: '0500013M026'
240
+ )
241
+ iban.iban # => "MC9320041010050500013M02606"
242
+
243
+ # The Netherlands
244
+ iban = Ibandit::IBANBuilder.build(
245
+ country_code: 'NL',
246
+ account_number: '0417164300',
247
+ bank_code: 'ABNA'
248
+ )
249
+ iban.iban # => "NL91ABNA0417164300"
250
+
251
+ # Portugal
252
+ iban = Ibandit::IBANBuilder.build(
253
+ country_code: 'PT',
254
+ bank_code: '0002',
255
+ branch_code: '0023',
256
+ account_number: '0023843000578'
257
+ )
258
+ iban.iban # => "PT50000200230023843000578"
259
+
260
+ # Slovakia
261
+ iban = Ibandit::IBANBuilder.build(
262
+ country_code: 'SK',
263
+ bank_code: '1200',
264
+ account_number_prefix: '19',
265
+ account_number: '8742637541'
266
+ )
267
+ iban.iban # => "SK3112000000198742637541"
268
+
269
+ # Slovenia
270
+ iban = Ibandit::IBANBuilder.build(
271
+ country_code: 'SI',
272
+ bank_code: '19100',
273
+ account_number: '1234'
274
+ )
275
+ iban.iban # => "SI56191000000123438"
276
+
277
+ # Spain
278
+ iban = Ibandit::IBANBuilder.build(
279
+ country_code: 'ES',
280
+ bank_code: '2310',
281
+ branch_code: '0001',
282
+ account_number: '180000012345'
283
+ )
284
+ iban.iban # => "ES8023100001180000012345"
285
+
286
+ # Spain with 20 digit account number
287
+ iban = Ibandit::IBANBuilder.build(
288
+ country_code: 'ES',
289
+ account_number: '23100001180000012345'
290
+ )
291
+ iban.iban # => "ES8023100001180000012345"
292
+
293
+ # San Marino
294
+ iban = Ibandit::IBANBuilder.build(
295
+ country_code: 'SM',
296
+ bank_code: '05428',
297
+ branch_code: '11101',
298
+ account_number: '000000123456'
299
+ )
300
+ iban.iban # => "SM88X0542811101000000123456"
301
+ ```
302
+
303
+ Support for Greece and Malta is coming soon.