bic_validation 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ - jruby-19mode
7
+ - jruby-head
8
+ - rbx-19mode
9
+ - rbx
10
+ - rbx-head
11
+ script: rspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Frank C. Eckert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # BicValidation
2
+
3
+ [![Build Status](https://travis-ci.org/opahk/bic_validation.png?branch=master)](https://travis-ci.org/opahk/bic_validation)
4
+
5
+ ActiveModel Business Identifier Code (BIC) validator
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'bic_validation'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install bic_validation
19
+
20
+ ## Usage
21
+
22
+ In your rails model
23
+
24
+ validates :bic_attribute, bic: true
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bic_validation/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bic_validation"
8
+ gem.version = BicValidation::VERSION
9
+ gem.authors = ["Frank C. Eckert"]
10
+ gem.email = ["frank.eckert@boost-project.com"]
11
+ gem.description = <<-EOF
12
+ BicValidation provides a simple ActiveModel::EachValidator for
13
+ formally validating Business Identifier Codes (BIC) aka SWIFT-codes.
14
+ EOF
15
+ gem.summary = %q{ActiveModel BIC validator}
16
+ gem.homepage = "https://github.com/opahk/bic_validation"
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+
23
+ gem.add_dependency 'activemodel'
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'coveralls'
26
+ gem.add_development_dependency 'pry'
27
+ end
@@ -0,0 +1,62 @@
1
+ module BicValidation
2
+ class Bic
3
+
4
+ def initialize(code)
5
+ @code = code.strip.upcase
6
+ end
7
+
8
+ def of_valid_length?
9
+ [8, 11].include? @code.length
10
+ end
11
+
12
+ def of_valid_format?
13
+ @code =~ format
14
+ end
15
+
16
+ def has_valid_country_code?
17
+ country_codes.include? country
18
+ end
19
+
20
+ def has_valid_branch_code?
21
+ # WTF? http://de.wikipedia.org/wiki/ISO_9362
22
+ country[0] =~ /[^01]/ && country[1] =~ /[^O]/
23
+ end
24
+
25
+ def valid?
26
+ of_valid_length? and
27
+ of_valid_format? and
28
+ has_valid_country_code?
29
+ end
30
+
31
+ def bank
32
+ match[1]
33
+ end
34
+
35
+ def country
36
+ match[2]
37
+ end
38
+
39
+ def location
40
+ match[3]
41
+ end
42
+
43
+ def branch
44
+ match[4]
45
+ end
46
+
47
+ private
48
+
49
+ def format
50
+ /([A-Z]{4})([A-Z]{2})([0-9A-Z]{2})([0-9A-Z]{3})?/
51
+ end
52
+
53
+ def match
54
+ format.match(@code)
55
+ end
56
+
57
+ def country_codes
58
+ # http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm
59
+ YAML.load(File.read(File.dirname(__FILE__) + '/country_codes.yml'))
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ module BicValidation
2
+ class BicValidator < ActiveModel::EachValidator
3
+ def validate_each(record, attribute, value)
4
+ unless Bic.new(value).valid?
5
+ record.errors.add attribute, 'is not a valid BIC'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,249 @@
1
+ AF
2
+ AX
3
+ AL
4
+ DZ
5
+ AS
6
+ AD
7
+ AO
8
+ AI
9
+ AQ
10
+ AG
11
+ AR
12
+ AM
13
+ AW
14
+ AU
15
+ AT
16
+ AZ
17
+ BS
18
+ BH
19
+ BD
20
+ BB
21
+ BY
22
+ BE
23
+ BZ
24
+ BJ
25
+ BM
26
+ BT
27
+ BO
28
+ BQ
29
+ BA
30
+ BW
31
+ BV
32
+ BR
33
+ IO
34
+ BN
35
+ BG
36
+ BF
37
+ BI
38
+ KH
39
+ CM
40
+ CA
41
+ CV
42
+ KY
43
+ CF
44
+ TD
45
+ CL
46
+ CN
47
+ CX
48
+ CC
49
+ CO
50
+ KM
51
+ CG
52
+ CD
53
+ CK
54
+ CR
55
+ CI
56
+ HR
57
+ CU
58
+ CW
59
+ CY
60
+ CZ
61
+ DK
62
+ DJ
63
+ DM
64
+ DO
65
+ EC
66
+ EG
67
+ SV
68
+ GQ
69
+ ER
70
+ EE
71
+ ET
72
+ FK
73
+ FO
74
+ FJ
75
+ FI
76
+ FR
77
+ GF
78
+ PF
79
+ TF
80
+ GA
81
+ GM
82
+ GE
83
+ DE
84
+ GH
85
+ GI
86
+ GR
87
+ GL
88
+ GD
89
+ GP
90
+ GU
91
+ GT
92
+ GG
93
+ GN
94
+ GW
95
+ GY
96
+ HT
97
+ HM
98
+ VA
99
+ HN
100
+ HK
101
+ HU
102
+ IS
103
+ IN
104
+ ID
105
+ IR
106
+ IQ
107
+ IE
108
+ IM
109
+ IL
110
+ IT
111
+ JM
112
+ JP
113
+ JE
114
+ JO
115
+ KZ
116
+ KE
117
+ KI
118
+ KP
119
+ KR
120
+ KW
121
+ KG
122
+ LA
123
+ LV
124
+ LB
125
+ LS
126
+ LR
127
+ LY
128
+ LI
129
+ LT
130
+ LU
131
+ MO
132
+ MK
133
+ MG
134
+ MW
135
+ MY
136
+ MV
137
+ ML
138
+ MT
139
+ MH
140
+ MQ
141
+ MR
142
+ MU
143
+ YT
144
+ MX
145
+ FM
146
+ MD
147
+ MC
148
+ MN
149
+ ME
150
+ MS
151
+ MA
152
+ MZ
153
+ MM
154
+ NA
155
+ NR
156
+ NP
157
+ NL
158
+ NC
159
+ NZ
160
+ NI
161
+ NE
162
+ NG
163
+ NU
164
+ NF
165
+ MP
166
+ NO
167
+ OM
168
+ PK
169
+ PW
170
+ PS
171
+ PA
172
+ PG
173
+ PY
174
+ PE
175
+ PH
176
+ PN
177
+ PL
178
+ PT
179
+ PR
180
+ QA
181
+ RE
182
+ RO
183
+ RU
184
+ RW
185
+ BL
186
+ SH
187
+ KN
188
+ LC
189
+ MF
190
+ PM
191
+ VC
192
+ WS
193
+ SM
194
+ ST
195
+ SA
196
+ SN
197
+ RS
198
+ SC
199
+ SL
200
+ SG
201
+ SX
202
+ SK
203
+ SI
204
+ SB
205
+ SO
206
+ ZA
207
+ GS
208
+ SS
209
+ ES
210
+ LK
211
+ SD
212
+ SR
213
+ SJ
214
+ SZ
215
+ SE
216
+ CH
217
+ SY
218
+ TW
219
+ TJ
220
+ TZ
221
+ TH
222
+ TL
223
+ TG
224
+ TK
225
+ TO
226
+ TT
227
+ TN
228
+ TR
229
+ TM
230
+ TC
231
+ TV
232
+ UG
233
+ UA
234
+ AE
235
+ GB
236
+ US
237
+ UM
238
+ UY
239
+ UZ
240
+ VU
241
+ VE
242
+ VN
243
+ VG
244
+ VI
245
+ WF
246
+ EH
247
+ YE
248
+ ZM
249
+ ZW
@@ -0,0 +1,3 @@
1
+ module BicValidation
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,9 @@
1
+ require "active_model"
2
+ require "bic_validation/bic"
3
+ require "bic_validation/bic_validator"
4
+ require "bic_validation/version"
5
+
6
+ module BicValidation
7
+ end
8
+
9
+ ActiveModel::Validations.send(:include, BicValidation)
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ module BicValidation
4
+ describe Bic do
5
+
6
+ describe '#valid?' do
7
+ bic = Bic.new "MARKDEFF"
8
+ bic.valid?.should == true
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_filter '/spec/'
10
+ end
11
+
12
+ require 'bic_validation'
13
+
14
+ RSpec.configure do |config|
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bic_validation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Frank C. Eckert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activemodel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: coveralls
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! " BicValidation provides a simple ActiveModel::EachValidator for\n
79
+ \ formally validating Business Identifier Codes (BIC) aka SWIFT-codes.\n"
80
+ email:
81
+ - frank.eckert@boost-project.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - .travis.yml
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - bic_validation.gemspec
94
+ - lib/bic_validation.rb
95
+ - lib/bic_validation/bic.rb
96
+ - lib/bic_validation/bic_validator.rb
97
+ - lib/bic_validation/country_codes.yml
98
+ - lib/bic_validation/version.rb
99
+ - spec/bic_validation/bic_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/opahk/bic_validation
102
+ licenses: []
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.25
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: ActiveModel BIC validator
125
+ test_files:
126
+ - spec/bic_validation/bic_spec.rb
127
+ - spec/spec_helper.rb
128
+ has_rdoc: