validates_swift 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +26 -0
- data/lib/swift-code-tool/README.md +27 -0
- data/lib/swift-code-tool/lib/swift-code.rb +59 -0
- data/lib/swift_validator.rb +14 -0
- data/lib/tasks/validates_swift_tasks.rake +4 -0
- data/lib/validates_swift/version.rb +3 -0
- data/lib/validates_swift.rb +4 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjQzYzVlN2Y4YmEyMmVlNzM3OGY2ZTE4NmQ5ZWIyOWE0ZmM3ODk3OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDkxNjlkYjExNzVkN2U4MjUwNmRlNjkwYjAzMTk3YTA3N2Y0YmExMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MGQwODUwMjVhZTNiMGMzYjIwNjE1NzAxMTNmYzQ1YzEzYTk4ZjZlZDhjNmEy
|
10
|
+
NDE3NmJiNDhiZWNhNjA2MTM4N2EyYWFlOGEzMDRlMTQ0MzYxOTJkYzI3NDU4
|
11
|
+
YmRmMzY0ZDM4ZDBmZjRiOGJjMGE0YTQxMGI1OGFjZTc0ODE0Y2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjQ1NGQyYjY1ODU1NzUwN2RhODc4NGI0ZjIyOTljODk4NjNlNzgwMzI3NGU5
|
14
|
+
NDY2NDk1ZWIyNThjYWQ4OWQ5MTg0MTFjZDJmYzg0NzU1MGQ4MjM0YjQ1ZGE4
|
15
|
+
ODkzNTE1NzVlNjBkNzFlNjNmNGU0ZWNjNDk2ODBmODljZWU1MjY=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
[![Build Status](https://api.shippable.com/projects/54a7c83ad46935d5fbc1625b/badge?branchName=master)](https://app.shippable.com/projects/54a7c83ad46935d5fbc1625b/builds/latest)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/kaspernj/validates_swift/badges/gpa.svg)](https://codeclimate.com/github/kaspernj/validates_swift)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/kaspernj/validates_swift/badges/coverage.svg)](https://codeclimate.com/github/kaspernj/validates_swift)
|
4
|
+
|
5
|
+
# ValidatesSwift
|
6
|
+
|
7
|
+
ActiveRecord validator for SWIFT codes using this project to do the actual validation:
|
8
|
+
https://github.com/marjaimate/swift-code-tool
|
9
|
+
|
10
|
+
This project rocks and uses MIT-LICENSE.
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add to Gemfile and bundle:
|
16
|
+
```ruby
|
17
|
+
gem "validates_swift"
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class Account < ActiveRecord::Base
|
24
|
+
validates :swift_string, swift: true
|
25
|
+
end
|
26
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'ValidatesSwift'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# SWIFT Code Tool
|
2
|
+
|
3
|
+
SWIFT (BIC) Code Tool for validating
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
sc = SWIFTCodeTool::SWIFT.new('deutdeff')
|
7
|
+
|
8
|
+
sc.code
|
9
|
+
=> "DEUTDEFF"
|
10
|
+
|
11
|
+
sc.bank_code
|
12
|
+
=> "DEUT"
|
13
|
+
|
14
|
+
sc.country_code
|
15
|
+
=> "DE"
|
16
|
+
|
17
|
+
sc.location_code
|
18
|
+
=> "FF"
|
19
|
+
|
20
|
+
sc.branch_code
|
21
|
+
=> ""
|
22
|
+
|
23
|
+
SWIFTCodeTool::SWIFT.valid?('DEUTDEFF')
|
24
|
+
=> true
|
25
|
+
|
26
|
+
SWIFTCodeTool::SWIFT.valid?('DEUT DE MU', 'de')
|
27
|
+
=> true
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#SWIFT / BIC code
|
2
|
+
#
|
3
|
+
# Format:
|
4
|
+
# BBBB CC LL XXX
|
5
|
+
#
|
6
|
+
# BBBB => Bank code
|
7
|
+
# CC => Country code
|
8
|
+
# LL => Location code
|
9
|
+
# XXX => Branch code, optional
|
10
|
+
|
11
|
+
module SWIFTCodeTool
|
12
|
+
class SWIFT
|
13
|
+
REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/
|
14
|
+
|
15
|
+
def initialize(code)
|
16
|
+
@code = SWIFT.canonicalize_code(code)
|
17
|
+
end
|
18
|
+
|
19
|
+
def code
|
20
|
+
@code
|
21
|
+
end
|
22
|
+
|
23
|
+
def bank_code
|
24
|
+
@code[0..3]
|
25
|
+
end
|
26
|
+
|
27
|
+
def country_code
|
28
|
+
@code[4..5]
|
29
|
+
end
|
30
|
+
|
31
|
+
def location_code
|
32
|
+
@code[6..7]
|
33
|
+
end
|
34
|
+
|
35
|
+
def branch_code
|
36
|
+
@code[8..10]
|
37
|
+
end
|
38
|
+
|
39
|
+
#escape whitespace and convert to uppercase
|
40
|
+
def self.canonicalize_code( code )
|
41
|
+
code.strip.gsub(/\s+/, '').upcase
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.valid?(code, country_code = nil)
|
45
|
+
new(code).validation_errors(country_code).empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
def validation_errors(expected_country_code)
|
49
|
+
errors = []
|
50
|
+
return [:unexpected_country_code] if not expected_country_code.nil? and (country_code != expected_country_code.upcase)
|
51
|
+
return [:too_short] if @code.size < 8
|
52
|
+
return [:too_long] if @code.size > 11
|
53
|
+
return [:bad_chars] unless @code =~ /^[A-Z0-9]+$/
|
54
|
+
errors << :bad_format unless @code =~ REGEX
|
55
|
+
errors
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "swift-code-tool/lib/swift-code"
|
2
|
+
|
3
|
+
class SwiftValidator < ActiveModel::EachValidator
|
4
|
+
def validate_each(object, attribute, value)
|
5
|
+
if value.present?
|
6
|
+
swift = SWIFTCodeTool::SWIFT.new(value)
|
7
|
+
errors = swift.validation_errors(nil)
|
8
|
+
|
9
|
+
unless errors.empty?
|
10
|
+
object.errors[attribute] << (options[:message] || "is not a valid SWIFT code: #{errors.join(", ")}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_swift
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kasper Johansen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: SWIFT validator for ActiveRecord attributes.
|
70
|
+
email:
|
71
|
+
- k@spernj.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/swift-code-tool/README.md
|
80
|
+
- lib/swift-code-tool/lib/swift-code.rb
|
81
|
+
- lib/swift_validator.rb
|
82
|
+
- lib/tasks/validates_swift_tasks.rake
|
83
|
+
- lib/validates_swift.rb
|
84
|
+
- lib/validates_swift/version.rb
|
85
|
+
homepage: https://www.github.com/kaspernj/validates_swift
|
86
|
+
licenses: []
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.3
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: SWIFT validator for ActiveRecord attributes.
|
108
|
+
test_files: []
|