iban_bic 0.1.0 → 1.0.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: c52896535d5704a64d38733ff91cd49356d4acda
4
- data.tar.gz: 569ccc510d44e3da5522caab6a45f805c34ea93a
3
+ metadata.gz: 868d6d3504a7634591fb05755ef16e2b7d97d0bf
4
+ data.tar.gz: d7d92fa69d618d303c37447ab204c4aa7d7e166c
5
5
  SHA512:
6
- metadata.gz: c9d1aa2265b7692f04fd562c6d0bc652e7108bf6283b7526259cd1c28b3181c470936d24609b267ab7ceb39240300c137aaa7d56667e75d5c05f473f894b079b
7
- data.tar.gz: b256ef1d47c347a273a56a0d1ff0e4bc3fead2be3d55131a52b5ae3a9c3c709c2db42740a8ba72fbc281e586a661985a0f9e3ec9617f3038a044aea7476408ed
6
+ metadata.gz: 7543c3a4b9be73644d210d1e119f82c8efc907bcd86402b4920ae6f1be63e2393e7690222ed6f720931800b5f19d1ee23ee522fc1d6ed1a4a0fac387f7fa114a
7
+ data.tar.gz: 7355d2ff4621e6a2574508cbf5987383084e5c0305c4c57f50b916c721904ec51c307805ab526409e5414967f58fa35d3fed10371c3deaf916556e2bdcea374e
data/README.md CHANGED
@@ -1,18 +1,20 @@
1
1
  # IBAN + BIC
2
2
  When IBAN validation is not enough.
3
3
 
4
+ [![Gem](https://img.shields.io/gem/v/iban_bic.svg)](https://rubygems.org/gems/iban_bic)
4
5
  [![Travis](https://img.shields.io/travis/podemos-info/iban_bic/master.svg)](https://travis-ci.org/podemos-info/iban_bic)
5
6
  [![Codecov](https://img.shields.io/codecov/c/github/podemos-info/iban_bic.svg)](https://codecov.io/gh/podemos-info/iban_bic)
6
7
  [![Scrutinizer](https://img.shields.io/scrutinizer/g/podemos-info/iban_bic.svg)](https://scrutinizer-ci.com/g/podemos-info/iban_bic/)
7
8
  [![Dependency Status](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/59d393190fb24f0046190d85?style=flat)
8
9
 
9
10
  ## Features
10
- * IBAN validation (`ActiveModel::EachValidator` and control digits calculator function).
11
- * National account digits control validation (currently only ES included, others countries can be added).
12
- * Associated tags to countries (currently only SEPA tag is available).
11
+ * IBAN validation (`ActiveModel::EachValidator` and control digits calculator function) and fixing.
12
+ * National account digits control validation (currently only ES and PT are included, others countries can be added).
13
+ * Associated tags to countries (currently only SEPA and FIXED_CHECK tags are available).
13
14
  * BICs mapping from IBAN bank code part: COUNTRY + BANK => BIC code.
14
15
  * Currently, static data only includes some ES banks, PRs are welcomed.
15
16
  * Optional database model to allow apps to dynamically add new BICs mapping.
17
+ * Random IBANs generator
16
18
 
17
19
  ## Usage
18
20
 
@@ -42,13 +44,37 @@ validates :iban, iban: { tags: [:sepa] }
42
44
  => {"country"=>"ES", "iban_check"=>"87", "bank"=>"0003", "branch"=>"0000", "check"=>"30", "account"=>"0000000000"}
43
45
  ```
44
46
 
45
- 4. BIC calculation (bank code must be in the static file or in the database)
47
+ 4. IBAN fixing (IBAN control digits and country control digits, if that code is available)
46
48
 
47
49
  ```ruby
48
- 2.4.1 :009 > IbanBic.calculate_bic("ES8700030000300000000000")
50
+ 2.4.1 :001 > IbanBic.fix("ES0000030000200000000000")
51
+ => "ES8700030000300000000000"
52
+ ```
53
+
54
+ 5. BIC calculation (bank code must be in the static file or in the database)
55
+
56
+ ```ruby
57
+ 2.4.1 :001 > IbanBic.calculate_bic("ES8700030000300000000000")
49
58
  => "BDEPESM1XXX"
50
59
  ```
51
60
 
61
+ 6. Random IBAN generation
62
+
63
+ ```ruby
64
+ 2.4.1 :001 > require "iban_bic/random"
65
+ => true
66
+ 2.4.1 :002 > IbanBic.random_iban
67
+ => "MU52BOIR2768144336487102000AWQ"
68
+ 2.4.1 :003 > IbanBic.random_iban country: "ES"
69
+ => "ES6111051493192369291292"
70
+ 2.4.1 :004 > IbanBic.random_iban tags: [:sepa]
71
+ => "FI5584518206233159"
72
+ 2.4.1 :005 > IbanBic.random_iban not_tags: [:sepa]
73
+ => "IL317532867920826062774"
74
+ ```
75
+
76
+ Note: It can't generate a valid IBAN code for some countries where iban check digits are fixed if validation code for that country is not available.
77
+
52
78
  ## Installation
53
79
 
54
80
  1. Add this line to your application's Gemfile
@@ -90,9 +116,17 @@ $ bundle exec rails generate iban_bic:install --with-static-data
90
116
 
91
117
  4. Customize initializer if needed, adding validations for new countries, or overriding YAML files.
92
118
 
93
- ## TO-DO
119
+ ## Changelog
120
+
121
+ #### 1.0.0
122
+
123
+ * Added IBAN fixing and random IBAN generator.
124
+
125
+ * Changed country checks, they must change check parts to generate the correct IBAN. Comparison against the original IBAN is made by the caller.
126
+
127
+ #### 0.1.0
94
128
 
95
- * Faker data generation
129
+ * First version.
96
130
 
97
131
  ## Contributing
98
132
  Contribution directions go here.
data/data/iban_meta.yml CHANGED
@@ -12,18 +12,18 @@ AZ:
12
12
  tags:
13
13
  BA:
14
14
  parts: (?<iban_check>39) (?<bank>\d{3}) (?<branch>\d{3}) (?<account>\d{8}) (?<check>\d{2})
15
- tags:
15
+ tags: fixed_iban_check
16
16
  BE:
17
17
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<account>\d{7}) (?<check>\d{2})
18
18
  tags: sepa
19
19
  BG:
20
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{4}) \d{2} (?<account>[A-Z0-9]{8})
20
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{4}) (?<type>\d{2}) (?<account>[A-Z0-9]{8})
21
21
  tags: sepa
22
22
  BH:
23
23
  parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{14})
24
24
  tags:
25
25
  BR:
26
- parts: (?<iban_check>\d{2}) (?<bank>\d{8}) (?<branch>\d{5}) (?<account>\d{10}) [A-Z][A-Z0-9]
26
+ parts: (?<iban_check>\d{2}) (?<bank>\d{8}) (?<branch>\d{5}) (?<account>\d{10}) (?<type>[A-Z]) (?<number>[A-Z0-9])
27
27
  tags:
28
28
  CH:
29
29
  parts: (?<iban_check>\d{2}) (?<bank>\d{5}) (?<account>[A-Z0-9]{12})
@@ -62,19 +62,19 @@ FR:
62
62
  parts: (?<iban_check>\d{2}) (?<bank>\d{5}) (?<branch>\d{5}) (?<account>[A-Z0-9]{11}) (?<check>\d{2})
63
63
  tags: sepa
64
64
  GB:
65
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{6}) (?<account>\d{8})
65
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{6}) (?<account>\d{8})
66
66
  tags: sepa
67
67
  GE:
68
68
  parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{2}) (?<account>\d{16})
69
69
  tags:
70
70
  GI:
71
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{15})
71
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{15})
72
72
  tags: sepa
73
73
  GR:
74
74
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<branch>\d{4}) (?<account>[A-Z0-9]{16})
75
75
  tags: sepa
76
76
  GT:
77
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z0-9]{4}) [A-Z0-9]{2} [A-Z0-9]{2} (?<account>[A-Z0-9]{16})
77
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z0-9]{4}) (?<currency>[A-Z0-9]{2}) (?<type>[A-Z0-9]{2}) (?<account>[A-Z0-9]{16})
78
78
  tags:
79
79
  HR:
80
80
  parts: (?<iban_check>\d{2}) (?<bank>\d{7}) (?<account>\d{10})
@@ -83,7 +83,7 @@ HU:
83
83
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<branch>\d{4}) (?<check>\d) (?<account>\d{15}) (?<check2>\d)
84
84
  tags: sepa
85
85
  IE:
86
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{6}) (?<account>\d{8})
86
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{6}) (?<account>\d{8})
87
87
  tags: sepa
88
88
  IL:
89
89
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<branch>\d{3}) (?<account>\d{13})
@@ -113,7 +113,7 @@ LU:
113
113
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<account>[A-Z0-9]{13})
114
114
  tags: sepa
115
115
  LV:
116
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{13})
116
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{13})
117
117
  tags: sepa
118
118
  MC:
119
119
  parts: (?<iban_check>\d{2}) (?<bank>\d{5}) (?<branch>\d{5}) (?<account>[A-Z0-9]{11}) (?<check>\d{2})
@@ -131,15 +131,15 @@ MR:
131
131
  parts: (?<iban_check>\d{2}) (?<bank>\d{5}) (?<branch>\d{5}) (?<account>\d{11}) (?<check>\d{2})
132
132
  tags:
133
133
  MT:
134
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{5}) (?<account>[A-Z0-9]{18})
134
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<branch>\d{5}) (?<account>[A-Z0-9]{18})
135
135
  tags: sepa
136
136
  MU:
137
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}\d{2}) (?<branch>\d{2}) (?<account>\d{12}) 000[A-Z]{3}
137
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}\d{2}) (?<branch>\d{2}) (?<account>\d{12}) (?<zeros>000) (?<currency>[A-Z]{3})
138
138
  tags:
139
139
  NL:
140
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>\d{10})
140
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>\d{10})
141
141
  tags: sepa
142
- NO:
142
+ "NO":
143
143
  parts: (?<iban_check>\d{2}) (?<bank>\d{4}) (?<account>\d{6}) (?<check>\d)
144
144
  tags: sepa
145
145
  PK:
@@ -149,23 +149,23 @@ PL:
149
149
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<branch>\d{4}) (?<check>\d) (?<account>\d{16})
150
150
  tags: sepa
151
151
  PS:
152
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z0-9]{4}) \d{9} (?<account>\d{12})
152
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z0-9]{4}) (?<unknown>\d{9}) (?<account>\d{12})
153
153
  tags:
154
154
  PT:
155
155
  parts: (?<iban_check>50) (?<bank>\d{4}) (?<branch>\d{4}) (?<account>\d{11}) (?<check>\d{2})
156
- tags: sepa
156
+ tags: sepa fixed_iban_check
157
157
  RO:
158
- parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{16})
158
+ parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>[A-Z0-9]{16})
159
159
  tags: sepa
160
160
  RS:
161
- parts: (?<iban_check>35) (?<bank>\d{3}) (?<account>\d{13}) (?<check>\d{2})
162
- tags:
161
+ parts: (?<iban_check>35) (?<bank>\d{3}) (?<account>\d{13}) (?<check>\d{2})
162
+ tags: fixed_iban_check
163
163
  SE:
164
164
  parts: (?<iban_check>\d{2}) (?<bank>\d{3}) (?<account>\d{17})
165
165
  tags: sepa
166
166
  SI:
167
167
  parts: (?<iban_check>56) (?<bank>\d{2}) (?<branch>\d{3}) (?<account>\d{8}) (?<check>\d{2})
168
- tags: sepa
168
+ tags: sepa fixed_iban_check
169
169
  SK:
170
170
  parts: (?<iban_check>\d{2}) (?<bank>\d{4}) (?<branch>\d{6}) (?<account>\d{10})
171
171
  tags: sepa
@@ -173,10 +173,10 @@ SM:
173
173
  parts: (?<iban_check>\d{2}) (?<check>[A-Z]) (?<bank>\d{5}) (?<branch>\d{5}) (?<account>[A-Z0-9]{12})
174
174
  tags: sepa
175
175
  TN:
176
- parts: (?<iban_check>59) (?<bank>\d{2}) (?<branch>\d{3}) (?<account>\d{15})
177
- tags:
176
+ parts: (?<iban_check>59) (?<bank>\d{2}) (?<branch>\d{3}) (?<account>\d{13}) (?<check>\d{2})
177
+ tags: fixed_iban_check
178
178
  TR:
179
- parts: (?<iban_check>\d{2}) (?<bank>\d{5}) 0 (?<account>[A-Z0-9]{16})
179
+ parts: (?<iban_check>\d{2}) (?<bank>\d{5}) (?<zeros>0) (?<account>[A-Z0-9]{16})
180
180
  tags: sepa
181
181
  VG:
182
182
  parts: (?<iban_check>\d{2}) (?<bank>[A-Z]{4}) (?<account>\d{16})
@@ -5,7 +5,7 @@ IbanBic.configure do |config|
5
5
  config.use_static_bics = <%= static_bics? %>
6
6
 
7
7
  # add [country_code] do |parts|
8
- # Here test that parts (bank, branch, account and/or check) satifies national checks
8
+ # Here change the check parts (check, check2) to make other parts (bank, branch, account) satify country checks
9
9
  # end
10
10
 
11
11
  # config.iban_meta_path = "path/iban_meta.yml"
@@ -4,12 +4,8 @@ module IbanBic
4
4
  class Configuration
5
5
  attr_accessor :iban_meta_path, :use_static_bics, :bics_table_name, :static_bics_path
6
6
 
7
- def country_validators
8
- @country_validators ||= {}
9
- end
10
-
11
7
  def add(country)
12
- country_validators[country] = Proc.new
8
+ IbanBic.country_validators[country] = Proc.new
13
9
  end
14
10
 
15
11
  def static_bics?
data/lib/iban_bic/core.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbanBic
4
+ @cached_variables = []
5
+
4
6
  module_function
5
7
 
8
+ def country_validators
9
+ @country_validators ||= {}
10
+ end
11
+
6
12
  def configuration
7
13
  @configuration ||= Configuration.new
8
14
  end
@@ -16,6 +22,34 @@ module IbanBic
16
22
  parts ? ActiveSupport::HashWithIndifferentAccess[parts.names.zip(parts.captures)] : nil
17
23
  end
18
24
 
25
+ def fix(iban)
26
+ # Fixed check IBAN parts (countries where IBAN check is always the same) must be fixed before parsing
27
+ iban, fixed_iban_check = fix_fixed_iban_check(iban)
28
+
29
+ parts = parse(iban)
30
+ return unless parts
31
+
32
+ iban = calculate_valid_country_check_iban(iban)
33
+ iban = fix_iban_check(iban) unless fixed_iban_check
34
+
35
+ iban
36
+ end
37
+
38
+ def fix_fixed_iban_check(iban)
39
+ return [iban, false] unless tags[iban[0..1]].member?(:fixed_iban_check)
40
+
41
+ result = iban.dup
42
+ result[2..3] = /\(\?\<iban_check>([^\)]*)\)/.match(iban_meta[iban[0..1]]["parts"])[1]
43
+ [result, true]
44
+ end
45
+
46
+ def fix_iban_check(iban)
47
+ result = iban.dup
48
+ result[2..3] = "00"
49
+ result[2..3] = calculate_check(result).to_s.rjust(2, "0")
50
+ result.freeze
51
+ end
52
+
19
53
  def has_tags?(iban, searched_tags)
20
54
  (tags[iban[0..1]] & searched_tags).any?
21
55
  end
@@ -30,14 +64,25 @@ module IbanBic
30
64
  end .join.to_i % 97
31
65
  end
32
66
 
67
+ def valid?(iban)
68
+ valid_check?(iban) && valid_country_check?(iban)
69
+ end
70
+
33
71
  def valid_check?(iban)
34
72
  calculate_check(iban) == 97
35
73
  end
36
74
 
37
- def valid_country_check?(iban)
75
+ def calculate_valid_country_check_iban(iban)
76
+ validator = country_validators[iban[0..1]]
77
+ return iban unless validator
78
+
38
79
  parts = parse(iban)
39
- validator = IbanBic.configuration.country_validators[parts[:country]]
40
- validator.nil? || validator.call(parts)
80
+ validator.call(parts)
81
+ parts.values.join
82
+ end
83
+
84
+ def valid_country_check?(iban)
85
+ calculate_valid_country_check_iban(iban) == iban
41
86
  end
42
87
 
43
88
  def calculate_bic(iban)
@@ -49,23 +94,34 @@ module IbanBic
49
94
  end
50
95
 
51
96
  def clear_cache
52
- @parser = @static_bics = @dynamic_bics = nil
97
+ @cached_variables.each { |variable| instance_variable_set(variable, nil) }
98
+ @cached_variables.clear
99
+ end
100
+
101
+ def iban_meta
102
+ @iban_meta ||= ::YAML.load_file(configuration.iban_meta_path)
53
103
  end
54
104
 
55
105
  def parser
56
- @parser ||= Hash[
57
- ::YAML.load_file(configuration.iban_meta_path).map do |country, meta|
58
- [country, /^(?<country>#{country})#{meta["parts"].delete(" ")}$/]
59
- end
60
- ].freeze
106
+ @parser ||= begin
107
+ @cached_variables << :@parser
108
+ Hash[
109
+ iban_meta.map do |country, meta|
110
+ [country, /^(?<country>#{country})#{meta["parts"].delete(" ")}$/]
111
+ end
112
+ ].freeze
113
+ end
61
114
  end
62
115
 
63
116
  def tags
64
- @tags ||= Hash[
65
- ::YAML.load_file(configuration.iban_meta_path).map do |country, meta|
66
- [country, meta["tags"]&.split&.map(&:to_sym) || []]
67
- end
68
- ].freeze
117
+ @tags ||= begin
118
+ @cached_variables << :@tags
119
+ Hash[
120
+ iban_meta.map do |country, meta|
121
+ [country, meta["tags"]&.split&.map(&:to_sym) || []]
122
+ end
123
+ ].freeze
124
+ end
69
125
  end
70
126
 
71
127
  def bics
@@ -73,13 +129,17 @@ module IbanBic
73
129
  end
74
130
 
75
131
  def static_bics
76
- @static_bics ||= Hash[Dir.glob(File.join(configuration.static_bics_path, "*.yml")).map do |file|
77
- [File.basename(file).delete(".yml").upcase, YAML.load_file(file)]
78
- end].freeze
132
+ @static_bics ||= begin
133
+ @cached_variables << :@static_bics
134
+ Hash[Dir.glob(File.join(configuration.static_bics_path, "*.yml")).map do |file|
135
+ [File.basename(file).delete(".yml").upcase, YAML.load_file(file)]
136
+ end].freeze
137
+ end
79
138
  end
80
139
 
81
140
  def dynamic_bics
82
141
  @dynamic_bics ||= begin
142
+ @cached_variables << :@dynamic_bics
83
143
  ret = {}
84
144
  Bic.find_each do |bic|
85
145
  ret[bic.country] = {} unless ret[bic.country]
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "iban_bic/validators/countries/es.rb"
4
+ require "iban_bic/validators/countries/pt.rb"
4
5
 
5
6
  IbanBic.configure do |config|
6
7
  config.iban_meta_path = File.expand_path("../../data/iban_meta.yml", __dir__)
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "regexp-examples"
4
+
5
+ module IbanBic
6
+ module_function
7
+
8
+ def random_iban(options = {})
9
+ country = options[:country]
10
+ searched_tags = options[:tags]
11
+ non_searched_tags = options[:not_tags]
12
+
13
+ unless country
14
+ possible_countries = random_generator.keys
15
+ possible_countries -= IbanBic.tags.select { |_country, country_tags| (searched_tags - country_tags).any? } .keys if searched_tags.present?
16
+ possible_countries -= IbanBic.tags.select { |_country, country_tags| (non_searched_tags & country_tags).any? } .keys if non_searched_tags.present?
17
+ country = possible_countries.sample
18
+ end
19
+ IbanBic.fix(random_generator[country].random_example)
20
+ end
21
+
22
+ def random_generator
23
+ @random_generator ||= begin
24
+ @cached_variables << :@random_generator
25
+ Hash[
26
+ iban_meta.map do |country, meta|
27
+ [country, /^#{country}#{meta["parts"].delete(" ").gsub(/\(\?\<\w+\>([^\)]*)\)/, "\\1")}$/]
28
+ end
29
+ ].freeze
30
+ end
31
+ end
32
+ end
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def __bic_validation_proc(digits)
4
- ret = 11 - digits.chars.each_with_index.sum { |x, i| x.to_i * 2**i } % 11
5
- ret < 10 ? ret : 11 - ret
6
- end
7
-
8
3
  IbanBic.configure do
4
+ def __iban_bic_es_bic_validation_proc(digits)
5
+ ret = 11 - digits.chars.each_with_index.sum { |x, i| x.to_i * 2**i } % 11
6
+ ret < 10 ? ret : 11 - ret
7
+ end
9
8
  add "ES" do |parts|
10
- parts[:check] == "#{__bic_validation_proc("00#{parts[:bank]}#{parts[:branch]}")}#{__bic_validation_proc(parts[:account])}"
9
+ parts[:check] = "#{__iban_bic_es_bic_validation_proc("00#{parts[:bank]}#{parts[:branch]}")}#{__iban_bic_es_bic_validation_proc(parts[:account])}"
11
10
  end
12
11
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ IbanBic.configure do
4
+ IBAN_BIC_PT_WEIGHTS_INDEX = [73, 17, 89, 38, 62, 45, 53, 15, 50, 5, 49, 34, 81, 76, 27, 90, 9, 30, 3].freeze
5
+
6
+ add "PT" do |parts|
7
+ nib = "#{parts[:bank]}#{parts[:branch]}#{parts[:account]}"
8
+ sum = nib.chars.map(&:to_i).zip(IBAN_BIC_PT_WEIGHTS_INDEX).map { |a| a.inject(:*) } .sum
9
+ parts[:check] = 98 - sum % 97
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbanBic
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.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: 0.1.0
4
+ version: 1.0.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-10-04 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: regexp-examples
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: codecov
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -129,10 +143,12 @@ files:
129
143
  - lib/iban_bic/defaults.rb
130
144
  - lib/iban_bic/engine.rb
131
145
  - lib/iban_bic/models/bic.rb
146
+ - lib/iban_bic/random.rb
132
147
  - lib/iban_bic/validators/countries/es.rb
148
+ - lib/iban_bic/validators/countries/pt.rb
133
149
  - lib/iban_bic/version.rb
134
150
  - lib/tasks/load_data.rake
135
- homepage: https://github.info/podemos-info/iban_bic
151
+ homepage: https://github.com/podemos-info/iban_bic
136
152
  licenses:
137
153
  - MIT
138
154
  metadata: {}