iso-iban 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/LICENSE.txt +8 -0
- data/README.markdown +45 -0
- data/Rakefile +19 -0
- data/data/iso-iban/specs.yaml +838 -0
- data/iso-iban.gemspec +42 -0
- data/lib/iso/iban.rb +324 -0
- data/lib/iso/iban/autoload.rb +5 -0
- data/lib/iso/iban/specification.rb +128 -0
- data/lib/iso/iban/version.rb +18 -0
- data/test/data/test_spec.yaml +23 -0
- data/test/lib/helper.rb +86 -0
- data/test/runner.rb +20 -0
- data/test/tmp/test_spec.yaml +23 -0
- data/test/unit/lib/iso/iban.rb +117 -0
- metadata +61 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems/version' # newer rubygems use this
|
5
|
+
rescue LoadError
|
6
|
+
require 'gem/version' # older rubygems use this
|
7
|
+
end
|
8
|
+
|
9
|
+
module ISO
|
10
|
+
class IBAN
|
11
|
+
|
12
|
+
# The version of the sorting gem.
|
13
|
+
# @note
|
14
|
+
# require 'iso/iban' loads the version.
|
15
|
+
#
|
16
|
+
Version = Gem::Version.new("0.0.1")
|
17
|
+
end
|
18
|
+
end
|
data/test/lib/helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'yaml'
|
5
|
+
require 'test/unit/assertions'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module Kernel
|
9
|
+
module_function
|
10
|
+
def reset_test_files
|
11
|
+
data_dir = "#{TEST_DIR}/data"
|
12
|
+
tmp_dir = "#{TEST_DIR}/tmp"
|
13
|
+
FileUtils.rm_r(tmp_dir) if File.directory?(tmp_dir)
|
14
|
+
FileUtils.cp_r(data_dir, tmp_dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_file(name)
|
18
|
+
"#{TEST_DIR}/tmp/#{name}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
module TestSuite
|
24
|
+
attr_accessor :name
|
25
|
+
end
|
26
|
+
|
27
|
+
module Kernel
|
28
|
+
def suite(name, &block)
|
29
|
+
klass = Class.new(Test::Unit::TestCase)
|
30
|
+
klass.extend TestSuite
|
31
|
+
klass.name = "Suite #{name}"
|
32
|
+
klass.class_eval(&block)
|
33
|
+
|
34
|
+
klass
|
35
|
+
end
|
36
|
+
module_function :suite
|
37
|
+
end
|
38
|
+
|
39
|
+
class Test::Unit::TestCase
|
40
|
+
def self.inherited(by)
|
41
|
+
by.init
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.init
|
46
|
+
@setups = []
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.setup(&block)
|
50
|
+
@setups ||= []
|
51
|
+
@setups << block
|
52
|
+
end
|
53
|
+
|
54
|
+
class << self
|
55
|
+
attr_reader :setups
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup
|
59
|
+
self.class.setups.each do |setup|
|
60
|
+
instance_eval(&setup)
|
61
|
+
end
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.suite(name, &block)
|
66
|
+
klass = Class.new(Test::Unit::TestCase)
|
67
|
+
klass.extend TestSuite
|
68
|
+
klass.name = "#{self.name} #{name}"
|
69
|
+
klass.class_eval(&block)
|
70
|
+
|
71
|
+
klass
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.test(desc, &impl)
|
75
|
+
define_method("test #{desc}", &impl)
|
76
|
+
end
|
77
|
+
|
78
|
+
def capture_stdout
|
79
|
+
captured = StringIO.new
|
80
|
+
$stdout = captured
|
81
|
+
yield
|
82
|
+
captured.string
|
83
|
+
ensure
|
84
|
+
$stdout = STDOUT
|
85
|
+
end
|
86
|
+
end
|
data/test/runner.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# run with `ruby test/runner.rb`
|
2
|
+
# if you only want to run a single test-file: `ruby test/runner.rb testfile.rb`
|
3
|
+
|
4
|
+
if ENV['COVERAGE']
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start
|
7
|
+
end
|
8
|
+
|
9
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
10
|
+
$LOAD_PATH << File.expand_path('../../test/lib', __FILE__)
|
11
|
+
TEST_DIR = File.expand_path('../../test', __FILE__)
|
12
|
+
|
13
|
+
require 'test/unit'
|
14
|
+
require 'helper'
|
15
|
+
|
16
|
+
units = ARGV.empty? ? Dir["#{TEST_DIR}/unit/**/*.rb"] : ARGV
|
17
|
+
|
18
|
+
units.each do |unit|
|
19
|
+
load unit
|
20
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'iso/iban'
|
4
|
+
|
5
|
+
suite "ISO::IBAN" do
|
6
|
+
setup do
|
7
|
+
ISO::IBAN.instance_variable_set(:@specifications, {'CH' => ISO::IBAN::Specification.new("Switzerland", "CH", "CH2!n5!n12!c", 21, "5!n12!c", 17, 4, 8, nil, nil)})
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'ISO::IBAN::load_specifications' do
|
11
|
+
reset_test_files
|
12
|
+
|
13
|
+
ISO::IBAN.load_specifications(test_file('test_spec.yaml'))
|
14
|
+
specs = ISO::IBAN.specifications
|
15
|
+
assert_kind_of Hash, specs
|
16
|
+
specs.each do |key, value|
|
17
|
+
assert_kind_of String, key
|
18
|
+
assert_kind_of ISO::IBAN::Specification, value
|
19
|
+
assert_equal key, value.a2_country_code
|
20
|
+
end
|
21
|
+
assert_equal ["AL", "AD"], specs.keys
|
22
|
+
end
|
23
|
+
|
24
|
+
test 'ISO::IBAN::numerify' do
|
25
|
+
assert_equal 121735123459876543210910, ISO::IBAN.numerify('CH351234598765432109A')
|
26
|
+
assert_raise ArgumentError do
|
27
|
+
ISO::IBAN.numerify('CH99 1234 5987 6543 2109 A')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'ISO::IBAN::generate' do
|
32
|
+
assert_equal 'CH76 0012 3000 0000 9876 B', ISO::IBAN.generate('CH', '123', '9876B').formatted
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'ISO::IBAN::valid?' do
|
36
|
+
assert ISO::IBAN.valid?('CH35 1234 5987 6543 2109 A')
|
37
|
+
assert !ISO::IBAN.valid?('CH99 1234 5987 6543 2109 A')
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'ISO::IBAN::validate' do
|
41
|
+
assert_equal [], ISO::IBAN.validate('CH35 1234 5987 6543 2109 A')
|
42
|
+
assert_equal [:invalid_checksum], ISO::IBAN.validate('CH99 1234 5987 6543 2109 A')
|
43
|
+
assert_equal [:invalid_format], ISO::IBAN.validate('CH86 X234 5987 6543 2109 A')
|
44
|
+
assert_equal [:invalid_checksum, :invalid_format], ISO::IBAN.validate('CH99 X234 5987 6543 2109 A')
|
45
|
+
assert_equal [:invalid_length, :invalid_format], ISO::IBAN.validate('CH83 X234 5987 6543 2109 AB')
|
46
|
+
assert_equal [:invalid_checksum, :invalid_length, :invalid_format], ISO::IBAN.validate('CH99 X234 5987 6543 2109 AB')
|
47
|
+
assert_equal [:invalid_country, :invalid_checksum, :invalid_length, :invalid_format], ISO::IBAN.validate('XX35 1234 5987 6543 2109 A')
|
48
|
+
end
|
49
|
+
|
50
|
+
test "ISO::IBAN::new" do
|
51
|
+
assert_kind_of ISO::IBAN, ISO::IBAN.new('CH35 1234 5987 6543 2109 A')
|
52
|
+
assert_kind_of ISO::IBAN, ISO::IBAN.new('CH351234598765432109A')
|
53
|
+
end
|
54
|
+
|
55
|
+
test "ISO::IBAN#formatted" do
|
56
|
+
assert_equal 'CH35 1234 5987 6543 2109 A', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').formatted
|
57
|
+
assert_equal 'CH35 1234 5987 6543 2109 A', ISO::IBAN.new('CH351234598765432109A').formatted
|
58
|
+
end
|
59
|
+
|
60
|
+
test "ISO::IBAN#compact" do
|
61
|
+
assert_equal 'CH351234598765432109A', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').compact
|
62
|
+
assert_equal 'CH351234598765432109A', ISO::IBAN.new('CH351234598765432109A').compact
|
63
|
+
end
|
64
|
+
|
65
|
+
test "ISO::IBAN#to_s" do
|
66
|
+
assert_equal 'CH351234598765432109A', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').to_s
|
67
|
+
assert_equal 'CH351234598765432109A', ISO::IBAN.new('CH351234598765432109A').to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
test "ISO::IBAN#country" do
|
71
|
+
assert_equal 'CH', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').country
|
72
|
+
end
|
73
|
+
|
74
|
+
test "ISO::IBAN#checksum_digits" do
|
75
|
+
assert_equal '35', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').checksum_digits
|
76
|
+
end
|
77
|
+
|
78
|
+
test "ISO::IBAN#bban" do
|
79
|
+
assert_equal '1234598765432109A', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').bban
|
80
|
+
end
|
81
|
+
|
82
|
+
test "ISO::IBAN#bank_code" do
|
83
|
+
assert_equal '12345', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').bank_code
|
84
|
+
end
|
85
|
+
|
86
|
+
test "ISO::IBAN#branch_code" do
|
87
|
+
ISO::IBAN.instance_variable_set(:@specifications, {'BG' => ISO::IBAN::Specification.new("Bulgaria", "BG", "BG2!n4!a4!n2!n8!c", 22, "4!a4!n2!n8!c", 18, 4, 7, 8, 11)})
|
88
|
+
assert_equal "0002", ISO::IBAN.new('BG69 0001 0002 0300 0000 04').branch_code
|
89
|
+
end
|
90
|
+
|
91
|
+
test "ISO::IBAN#account_code" do
|
92
|
+
assert_equal '98765432109A', ISO::IBAN.new('CH35 1234 5987 6543 2109 A').account_code
|
93
|
+
end
|
94
|
+
|
95
|
+
test "ISO::IBAN#valid?" do
|
96
|
+
assert_equal true, ISO::IBAN.new('CH35 1234 5987 6543 2109 A').valid?
|
97
|
+
assert_equal false, ISO::IBAN.new('CH99 1234 5987 6543 2109 A').valid?
|
98
|
+
end
|
99
|
+
|
100
|
+
test "ISO::IBAN#validate" do
|
101
|
+
assert_equal [], ISO::IBAN.new('CH35 1234 5987 6543 2109 A').validate
|
102
|
+
end
|
103
|
+
|
104
|
+
test "ISO::IBAN#<=>" do
|
105
|
+
iban0 = ISO::IBAN.generate('CH', '0', '0')
|
106
|
+
iban1 = ISO::IBAN.generate('CH', '0', '97') # 97 to have the same checksum
|
107
|
+
assert_equal -1, iban0 <=> iban1
|
108
|
+
assert_equal 0, iban0 <=> iban0
|
109
|
+
assert_equal 1, iban1 <=> iban0
|
110
|
+
assert_equal nil, iban0 <=> "incomparable"
|
111
|
+
assert_equal nil, "incomparable" <=> iban0
|
112
|
+
end
|
113
|
+
|
114
|
+
test "ISO::IBAN#inspect" do
|
115
|
+
assert_equal "#<ISO::IBAN CH35 1234 5987 6543 2109 A>", ISO::IBAN.new('CH35 1234 5987 6543 2109 A').inspect
|
116
|
+
end
|
117
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iso-iban
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Rusterholz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
ISO::IBAN implements IBAN (International Bank Account Number) specification as per ISO 13616-1.
|
15
|
+
It provides methods to generate valid IBAN numbers from components, or to validate a given IBAN.
|
16
|
+
email: stefan.rusterholz@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- data/iso-iban/specs.yaml
|
22
|
+
- lib/iso/iban/autoload.rb
|
23
|
+
- lib/iso/iban/specification.rb
|
24
|
+
- lib/iso/iban/version.rb
|
25
|
+
- lib/iso/iban.rb
|
26
|
+
- test/data/test_spec.yaml
|
27
|
+
- test/lib/helper.rb
|
28
|
+
- test/runner.rb
|
29
|
+
- test/tmp/test_spec.yaml
|
30
|
+
- test/unit/lib/iso/iban.rb
|
31
|
+
- iso-iban.gemspec
|
32
|
+
- .yardopts
|
33
|
+
- LICENSE.txt
|
34
|
+
- Rakefile
|
35
|
+
- README.markdown
|
36
|
+
homepage: https://github.com/apeiros/iso-iban
|
37
|
+
licenses:
|
38
|
+
- BSD 2-Clause
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.9.2
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - '>'
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.3.1
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.3
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: Utilities for International Bank Account Numbers (IBAN) as per ISO 13616-1.
|
60
|
+
test_files: []
|
61
|
+
has_rdoc:
|