iban_bic 1.3.0 → 1.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ceee574baf89047cca1c43e4a56867d1a21c5765
4
- data.tar.gz: aca6662efc0a326032265cd136d700da947c7010
3
+ metadata.gz: f7b2f833a71bf207363496a6140a16d97de02395
4
+ data.tar.gz: d35302a1fdd34187d969477b0205eabd45ba795d
5
5
  SHA512:
6
- metadata.gz: 620962ed8c778c9a76fa26bad91bf8893761caa57d48f8468eb3dd2ac8e3b59845ddee9c9ddfa2916571827a3448421d6b30280b5844c8cbcc57bf980b32478c
7
- data.tar.gz: bfb982acd2ed33a89d7da67d115d9bee90e9681a070f2f87d7a3ffc606b0fdc87113f10413995105f870f17dd9ff8e1baec7d3825fe8b2eab136420e31da5686
6
+ metadata.gz: 45b4e30101e361d6f92d0d9441574a3d0d03cbea192667194cee19935822d90b325257eb446e083b8411b0ce13d2455ea1915dc8e2b5b3c6c4434f356a61b770
7
+ data.tar.gz: 3ecf0d1ec09baf2850ac0b8fe640e8c6ee66e67947886b42854327186bcad59a17f927ebbd37c71c4b93928204889d62ba0a40acc2874047b0c93a2f375f76b9
data/README.md CHANGED
@@ -8,8 +8,9 @@ When IBAN validation is not enough.
8
8
  [![Dependency Status](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85?style=flat)
9
9
 
10
10
  ## Features
11
- * IBAN validation (`ActiveModel::EachValidator` and control digits calculator function) and fixing.
11
+ * IBAN and BIC validation (using `ActiveModel::EachValidator`, IBAN control digits calculator function).
12
12
  * National account digits control validation (currently only ES and PT are included, others countries can be added).
13
+ * IBAN fixing (global and national control digits).
13
14
  * Associated tags to countries (currently only SEPA and FIXED_CHECK tags are available).
14
15
  * BICs mapping from IBAN bank code part: COUNTRY + BANK => BIC code.
15
16
  * Currently, static data only includes some ES banks, PRs are welcomed.
@@ -18,7 +19,7 @@ When IBAN validation is not enough.
18
19
 
19
20
  ## Usage
20
21
 
21
- 1. Validator: add IBAN validation to your models.
22
+ 1. IBAN validator: add IBAN validation to your models.
22
23
 
23
24
  ```ruby
24
25
  validates :iban, iban: true
@@ -30,35 +31,48 @@ You can also validate that IBAN is from a SEPA country.
30
31
  validates :iban, iban: { tags: [:sepa] }
31
32
  ```
32
33
 
33
- 2. IBAN control digits calculation
34
+ 2. BIC validator: add BIC validation to your models.
35
+
36
+ ```ruby
37
+ validates :bic, bic: true
38
+ ```
39
+
40
+ You can specify the country field in the record to enforce its inclusion in the given BIC.
41
+
42
+ ```ruby
43
+ validates :bic, bic: { country: :pais }
44
+ ```
45
+
46
+
47
+ 3. IBAN control digits calculation
34
48
 
35
49
  ```ruby
36
50
  2.4.1 :001 > IbanBic.calculate_check("ES0000030000300000000000")
37
51
  => 87
38
52
  ```
39
53
 
40
- 3. IBAN parsing
54
+ 4. IBAN parsing
41
55
 
42
56
  ```ruby
43
57
  2.4.1 :001 > IbanBic.parse("ES8700030000300000000000")
44
58
  => {"country"=>"ES", "iban_check"=>"87", "bank"=>"0003", "branch"=>"0000", "check"=>"30", "account"=>"0000000000"}
45
59
  ```
46
60
 
47
- 4. IBAN fixing (IBAN control digits and country control digits, if that code is available)
61
+ 5. IBAN fixing (IBAN control digits and country control digits, if that code is available)
48
62
 
49
63
  ```ruby
50
64
  2.4.1 :001 > IbanBic.fix("ES0000030000200000000000")
51
65
  => "ES8700030000300000000000"
52
66
  ```
53
67
 
54
- 5. BIC calculation (bank code must be in the static file or in the database)
68
+ 6. BIC calculation (bank code must be in the static file or in the database)
55
69
 
56
70
  ```ruby
57
71
  2.4.1 :001 > IbanBic.calculate_bic("ES8700030000300000000000")
58
72
  => "BDEPESM1XXX"
59
73
  ```
60
74
 
61
- 6. Pattern generation for SQL LIKE queries.
75
+ 7. Pattern generation for SQL LIKE queries.
62
76
 
63
77
  ```ruby
64
78
  2.4.1 :001 > IbanBic.like_pattern("ES8700030000300000000000", :country, :bank)
@@ -67,7 +81,7 @@ validates :iban, iban: { tags: [:sepa] }
67
81
  => "ES__0003________________"
68
82
  ```
69
83
 
70
- 7. Random IBAN generation
84
+ 8. Random IBAN generation
71
85
 
72
86
  ```ruby
73
87
  2.4.1 :001 > require "iban_bic/random"
@@ -98,7 +112,7 @@ gem "iban_bic"
98
112
  $ bundle
99
113
  ```
100
114
 
101
- 3. Run installer
115
+ 3. If you will use this gem for BIC calculations or want to add additional country control codes validations, choose from any of the following two options to run the installer:
102
116
 
103
117
  3.a. Using BICs dynamic data from database
104
118
 
@@ -126,6 +140,10 @@ $ bundle exec rails generate iban_bic:install --with-static-data
126
140
  4. Customize initializer if needed, adding validations for new countries, or overriding YAML files.
127
141
 
128
142
  ## Changelog
143
+ #### 1.4.0
144
+
145
+ * BIC validation moved from BIC model to an independent validator.
146
+
129
147
  #### 1.3.0
130
148
 
131
149
  * Added BIC format validation in BIC model.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_model/validations"
4
+ require "iban_bic"
5
+
6
+ # ActiveModel Rails module.
7
+ module ActiveModel
8
+ # ActiveModel::Validations Rails module. Contains all the default validators.
9
+ module Validations
10
+ class BicValidator < ActiveModel::EachValidator
11
+ def validate_each(record, attribute, value)
12
+ country_field = options[:country] ? record[options[:country]] : "[A-Z]{2}"
13
+ unless /[A-Z]{4}#{country_field}[0-9A-Z]{2,5}/.match? value.upcase
14
+ record.errors.add(attribute, :invalid_format)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_model/validations/bic_validator"
3
4
  require "active_model/validations/iban_validator"
4
5
 
5
6
  module IbanBic
@@ -4,13 +4,7 @@ class Bic < ActiveRecord::Base
4
4
  self.table_name = IbanBic.configuration.bics_table_name
5
5
 
6
6
  validates :country, :bank_code, :bic, presence: true
7
-
8
- validate do
9
- bic.upcase!
10
- unless /[A-Z]{4}#{country}[0-9A-Z]{2,5}/.match? bic
11
- errors.add(:bic, :invalid_format)
12
- end
13
- end
7
+ validates :bic, bic: { country: :country }
14
8
 
15
9
  after_commit do
16
10
  IbanBic.clear_cache
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbanBic
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iban_bic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Diez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-13 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -133,6 +133,7 @@ files:
133
133
  - Rakefile
134
134
  - data/bics/es.yml
135
135
  - data/iban_meta.yml
136
+ - lib/active_model/validations/bic_validator.rb
136
137
  - lib/active_model/validations/iban_validator.rb
137
138
  - lib/generators/iban_bic/install_generator.rb
138
139
  - lib/generators/iban_bic/templates/create_bics.rb.erb