valiban 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -0
- data/lib/valiban.rb +25 -0
- data/lib/valiban/iban.rb +59 -0
- data/lib/valiban/iban_rules.yml +11 -0
- data/lib/valiban/rules.rb +20 -0
- metadata +66 -0
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# valiban
|
2
|
+
valiban converts IBAN code into bank account numbers and bank code numbers.
|
3
|
+
In the future, it will also support validation of IBAN codes.
|
4
|
+
|
5
|
+
## Credit
|
6
|
+
Some of the basic ideas of this gem were taken from iulianu's iban-tools
|
7
|
+
You'll find the [source code](http://github.com/iulianu/iban-tools) on Github.
|
8
|
+
|
9
|
+
## INSTALLATION
|
10
|
+
|
11
|
+
gem install valiban
|
12
|
+
|
13
|
+
## USAGE
|
14
|
+
|
15
|
+
require 'valiban'
|
16
|
+
|
17
|
+
### Get the bank code number
|
18
|
+
|
19
|
+
Valiban::IBAN.get_bank_code_number("AT754805700005040015")
|
20
|
+
=> "48057"
|
21
|
+
|
22
|
+
### Get the bank account number
|
23
|
+
|
24
|
+
Valiban::IBAN.get_bank_account_number("AT754805700005040015")
|
25
|
+
=> "00005040015"
|
26
|
+
|
27
|
+
### Get the country code
|
28
|
+
|
29
|
+
Valiban::IBAN.get_country_code("AT754805700005040015")
|
30
|
+
=> "AT"
|
31
|
+
|
32
|
+
|
33
|
+
## Future
|
34
|
+
|
35
|
+
- I also want to add validations for IBAN codes in the future.
|
36
|
+
- Add more country rules.
|
37
|
+
- Maybe I extend this library to deal with BIC/SWIFT codes as well
|
38
|
+
|
39
|
+
|
data/lib/valiban.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2013 Jürgen Brüder
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following 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 OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'valiban/iban.rb'
|
25
|
+
require 'valiban/rules.rb'
|
data/lib/valiban/iban.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Based on iban-tools by iulianu
|
2
|
+
# https://github.com/iulianu/iban-tools
|
3
|
+
|
4
|
+
module Valiban
|
5
|
+
|
6
|
+
class IBAN
|
7
|
+
|
8
|
+
def self.get_bank_code_number(code)
|
9
|
+
new(code).bank_code_number
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_bank_account_number(code)
|
13
|
+
new(code).bank_account_number
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_country_code(code)
|
17
|
+
new(code).country_code
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize( code )
|
21
|
+
@code = code
|
22
|
+
end
|
23
|
+
|
24
|
+
def base_length
|
25
|
+
4 #country_code + control_number always amount to 4
|
26
|
+
end
|
27
|
+
|
28
|
+
def code
|
29
|
+
@code
|
30
|
+
end
|
31
|
+
|
32
|
+
def country_code
|
33
|
+
@code[0..1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def bank_code_number
|
37
|
+
@code[base_length..bank_code_number_length]
|
38
|
+
end
|
39
|
+
|
40
|
+
def bank_account_number
|
41
|
+
@code[bank_account_number_start..@code.length]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Load and cache the default rules from rules.yml
|
45
|
+
def rules
|
46
|
+
@rules ||= Rules.load(self.country_code)
|
47
|
+
end
|
48
|
+
|
49
|
+
def bank_code_number_length
|
50
|
+
rules['bank_code_number_length'] + (base_length - 1)
|
51
|
+
end
|
52
|
+
|
53
|
+
def bank_account_number_start
|
54
|
+
bank_code_number_length + 1
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Based on iban-tools by iulianu
|
2
|
+
# https://github.com/iulianu/iban-tools
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Valiban
|
7
|
+
|
8
|
+
class Rules
|
9
|
+
|
10
|
+
def self.load(country_code)
|
11
|
+
begin
|
12
|
+
YAML.load(File.read(File.expand_path("../iban_rules.yml", __FILE__)))[country_code.downcase]
|
13
|
+
rescue Errno::ENOENT
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valiban
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jürgen Brüder
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.13.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.13.0
|
30
|
+
description: A gem to transform an IBAN number into europen account- and banknumbers
|
31
|
+
email: hello@juergenbrueder.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- README.md
|
37
|
+
- lib/valiban.rb
|
38
|
+
- lib/valiban/iban.rb
|
39
|
+
- lib/valiban/rules.rb
|
40
|
+
- lib/valiban/iban_rules.yml
|
41
|
+
homepage: https://github.com/jaybrueder/valiban
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements:
|
60
|
+
- none
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.25
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Valiban
|
66
|
+
test_files: []
|